Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
feat(money): add layout for create form in app
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Feb 18, 2019
1 parent 0760ac8 commit abecda5
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 34 deletions.
4 changes: 2 additions & 2 deletions front/src/features/app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CreateIncome } from './features/create-income'
import { CreateOutcome } from './features/create-outcome'
import { CreateIncome } from './features/create/create-income'
import { CreateOutcome } from './features/create/create-outcome'
import { History } from './features/history'
import { Stats } from './features/stats'

Expand Down
40 changes: 40 additions & 0 deletions front/src/features/app/features/create/SimpleForm.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.form {
display: grid;

grid-template-areas:
'title title title '
'amount source source '
'currency currency currency'
'date . submit ';

align-items: end;
max-width: 400px;
padding: 16px;
border: 1px solid black;
gap: 16px;
}

.title {
grid-area: title;
text-align: center;
}

.amount {
grid-area: amount;
}

.comment {
grid-area: source;
}

.date {
grid-area: date;
}

.currency {
grid-area: currency;
}

.submit {
grid-area: submit;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useCallback } from 'react'
import { Field, Form } from 'react-final-form'

import { Currency } from '@shared/enum/Currency'
import { IncomeModel } from '@shared/models/money/IncomeModel'

import { useCreateIncome } from '@front/domain/money/hooks/useCreateIncome'
import { Input, InputMoney } from '@front/features/final-form'
import { Button } from '@front/ui/atoms/button'
import { Label } from '@front/ui/atoms/label'
import { Currency } from '@shared/enum/Currency'
import { IncomeModel } from '@shared/models/money/IncomeModel'

import * as styles from '../SimpleForm.css'

export const CreateIncome = () => {
const create = useCreateIncome()
Expand All @@ -32,36 +33,39 @@ export const CreateIncome = () => {
{({ handleSubmit, form: { initialize }, values, initialValues }) => (
<form
onSubmit={e => handleSubmit(e)!.then(() => initialize(initialValues))}
className={styles.form}
>
<h2>Create new income</h2>
<h2 className={styles.title}>Create new income</h2>

<Label text="Amount">
<Label text="Amount" className={styles.amount}>
<InputMoney name="amount" currency={values.currency} />
</Label>

<Label text="Source">
<Label text="Source" className={styles.comment}>
<Input name="source" placeholder="NASA" />
</Label>

<Label text="Currency">
<Label text="Currency" className={styles.currency}>
{Object.values(Currency).map(value => (
<Label text={value} key={value} after>
<label key={value}>
<Field
name="currency"
component="input"
type="radio"
value={value}
key={value}
/>
</Label>
{value}
</label>
))}
</Label>

<Label text="Date">
<Label text="Date" className={styles.date}>
<Field name="date" component="input" type="date" />
</Label>

<Button submit>Create</Button>
<Button className={styles.submit} submit>
Create
</Button>
</form>
)}
</Form>
Expand Down
7 changes: 5 additions & 2 deletions front/src/ui/atoms/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { resolveType } from './helpers/resolveType'
interface Props {
submit?: boolean
children: string
className?: string
}

export const Button = ({ submit = false, children }: Props) => (
<AntButton htmlType={resolveType(submit)}>{children}</AntButton>
export const Button = ({ submit = false, children, className }: Props) => (
<AntButton htmlType={resolveType(submit)} className={className}>
{children}
</AntButton>
)
4 changes: 4 additions & 0 deletions front/src/ui/atoms/label/Label.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.text {
display: block;
padding-bottom: 8px;
}
21 changes: 7 additions & 14 deletions front/src/ui/atoms/label/Label.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import { ReactNode } from 'react'

import * as styles from './Label.css'

interface Props {
text: string
children: ReactNode
after?: boolean
className?: string
}

export const Label = ({ text, children, after = false }: Props) => (
<label>
{after ? (
<>
{children}
{text}
</>
) : (
<>
{text}
{children}
</>
)}
export const Label = ({ text, children, className }: Props) => (
<label className={className}>
<span className={styles.text}>{text}</span>
{children}
</label>
)
4 changes: 0 additions & 4 deletions front/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
declare module '*.css' {
const classes: { [key: string]: string }
export default classes
}

0 comments on commit abecda5

Please sign in to comment.