This repository has been archived by the owner on May 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from igorkamyshev/income-form
Income/Outcome form
- Loading branch information
Showing
51 changed files
with
1,592 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.app { | ||
display: grid; | ||
|
||
grid-template: | ||
'outcome income ' | ||
'history history' | ||
'stats stats ' | ||
/ 1fr 1fr; | ||
|
||
align-items: end; | ||
gap: 16px; | ||
padding: 24px; | ||
|
||
& > *:nth-child(odd) { | ||
justify-self: end; | ||
} | ||
|
||
& > *:nth-child(even) { | ||
justify-self: start; | ||
} | ||
|
||
@media (max-width: 576px) { | ||
grid-template: | ||
'outcome' | ||
'income' | ||
'history' | ||
'stats'; | ||
|
||
& > *:nth-child(even), | ||
& > *:nth-child(odd) { | ||
justify-self: stretch; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 0 additions & 78 deletions
78
front/src/features/app/features/create-income/CreateIncome.tsx
This file was deleted.
Oops, something went wrong.
78 changes: 0 additions & 78 deletions
78
front/src/features/app/features/create-outcome/CreateOutcome.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.container { | ||
max-width: 500px; | ||
|
||
@media (max-width: 768px) { | ||
width: 100%; | ||
} | ||
} | ||
|
||
.form { | ||
display: grid; | ||
|
||
grid-template: | ||
'amount currency' | ||
'comment comment ' | ||
'date submit ' | ||
/ 2fr minmax(150px, 1fr); | ||
|
||
@media (max-width: 768px) { | ||
grid-template: | ||
'amount' | ||
'currency' | ||
'comment' | ||
'date' | ||
'submit'; | ||
} | ||
|
||
align-items: end; | ||
gap: 16px; | ||
} | ||
|
||
.amount { | ||
grid-area: amount; | ||
} | ||
|
||
.comment { | ||
grid-area: comment; | ||
} | ||
|
||
.date { | ||
grid-area: date; | ||
} | ||
|
||
.currency { | ||
grid-area: currency; | ||
} | ||
|
||
.submit { | ||
grid-area: submit; | ||
} |
78 changes: 78 additions & 0 deletions
78
front/src/features/app/features/create/create-income/CreateIncome.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { useCallback } from 'react' | ||
import { Form } from 'react-final-form' | ||
|
||
import { useCreateIncome } from '@front/domain/money/hooks/useCreateIncome' | ||
import { | ||
DatePicker, | ||
EnumSelect, | ||
Input, | ||
InputMoney, | ||
} from '@front/features/final-form' | ||
import { getCurrencyName } from '@front/helpers/getCurrencyName' | ||
import { Button } from '@front/ui/atoms/button' | ||
import { Label } from '@front/ui/atoms/label' | ||
import { Card } from '@front/ui/molecules/card' | ||
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() | ||
|
||
const fieldsToIncomeModel = useCallback( | ||
({ amount, source, currency, date }: any): IncomeModel => ({ | ||
amount: Math.round(parseFloat(amount) * 100), | ||
currency, | ||
source, | ||
date, | ||
}), | ||
[], | ||
) | ||
|
||
const onSubmit = useCallback(async fields => { | ||
const income = fieldsToIncomeModel(fields) | ||
await create(income) | ||
}, []) | ||
|
||
return ( | ||
<Form | ||
onSubmit={onSubmit} | ||
initialValues={{ currency: Currency.RUB, date: new Date() }} | ||
> | ||
{({ handleSubmit, form: { initialize }, values, initialValues }) => ( | ||
<form | ||
onSubmit={e => handleSubmit(e)!.then(() => initialize(initialValues))} | ||
className={styles.container} | ||
> | ||
<Card title="Create new income" className={styles.form}> | ||
<Label text="Amount" className={styles.amount}> | ||
<InputMoney name="amount" currency={values.currency} /> | ||
</Label> | ||
|
||
<Label text="Source" className={styles.comment}> | ||
<Input name="source" placeholder="NASA" /> | ||
</Label> | ||
|
||
<Label text="Currency" className={styles.currency}> | ||
<EnumSelect | ||
showSearch | ||
name="currency" | ||
options={Currency} | ||
getLabel={getCurrencyName} | ||
/> | ||
</Label> | ||
|
||
<Label text="Date" className={styles.date}> | ||
<DatePicker name="date" /> | ||
</Label> | ||
|
||
<Button submit className={styles.submit}> | ||
Create | ||
</Button> | ||
</Card> | ||
</form> | ||
)} | ||
</Form> | ||
) | ||
} |
File renamed without changes.
Oops, something went wrong.