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 date to forms and reset after submit
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Feb 13, 2019
1 parent 60e7d38 commit a201d3a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 12 additions & 5 deletions front/src/features/app/features/create-income/CreateIncome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export const CreateIncome = () => {
const create = useCreateIncome()

const fieldsToIncomeModel = useCallback(
({ amount, source, currency }: any): IncomeModel => ({
({ amount, source, currency, date }: any): IncomeModel => ({
amount: Math.round(parseFloat(amount) * 100),
currency,
source,
date: new Date(),
date: !!date ? new Date(date) : new Date(),
}),
[],
)
Expand All @@ -26,8 +26,10 @@ export const CreateIncome = () => {

return (
<Form onSubmit={onSubmit} initialValues={{ currency: Currency.RUB }}>
{({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
{({ handleSubmit, form: { initialize }, initialValues }) => (
<form
onSubmit={e => handleSubmit(e)!.then(() => initialize(initialValues))}
>
<h2>Create new income</h2>

<div>
Expand All @@ -49,7 +51,7 @@ export const CreateIncome = () => {
<label>Source</label>
<div>
{Object.values(Currency).map(value => (
<label>
<label key={value}>
<Field
name="currency"
component="input"
Expand All @@ -63,6 +65,11 @@ export const CreateIncome = () => {
</div>
</div>

<div>
<label>Date</label>
<Field name="date" component="input" type="date" />
</div>

<button type="submit">create</button>
</form>
)}
Expand Down
17 changes: 12 additions & 5 deletions front/src/features/app/features/create-outcome/CreateOutcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export const CreateOutcome = () => {
const create = useCreateOutcome()

const fieldsToOutcomeModel = useCallback(
({ amount, category, currency }: any): OutcomeModel => ({
({ amount, category, currency, date }: any): OutcomeModel => ({
amount: Math.round(parseFloat(amount) * 100),
currency,
category,
date: new Date(),
date: !!date ? new Date(date) : new Date(),
}),
[],
)
Expand All @@ -26,8 +26,10 @@ export const CreateOutcome = () => {

return (
<Form onSubmit={onSubmit} initialValues={{ currency: Currency.RUB }}>
{({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
{({ handleSubmit, form: { initialize }, initialValues }) => (
<form
onSubmit={e => handleSubmit(e)!.then(() => initialize(initialValues))}
>
<h2>Create new outcome</h2>

<div>
Expand All @@ -49,7 +51,7 @@ export const CreateOutcome = () => {
<label>Source</label>
<div>
{Object.values(Currency).map(value => (
<label>
<label key={value}>
<Field
name="currency"
component="input"
Expand All @@ -63,6 +65,11 @@ export const CreateOutcome = () => {
</div>
</div>

<div>
<label>Date</label>
<Field name="date" component="input" type="date" />
</div>

<button type="submit">create</button>
</form>
)}
Expand Down

0 comments on commit a201d3a

Please sign in to comment.