From ca13a00d19eee4d0504c27c7f91dec623e18795c Mon Sep 17 00:00:00 2001 From: mmv Date: Thu, 18 Jul 2019 19:06:59 +0400 Subject: [PATCH] reset form when the only owner left is initial one --- src/components/Stepper/index.jsx | 1 + src/components/forms/GnoForm/index.jsx | 1 - .../SafeOwnersConfirmationsForm/index.jsx | 23 ++++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/components/Stepper/index.jsx b/src/components/Stepper/index.jsx index 9c69ec5e..dcca07cf 100644 --- a/src/components/Stepper/index.jsx +++ b/src/components/Stepper/index.jsx @@ -112,6 +112,7 @@ const GnoStepper = (props: Props) => { steps, children, classes, disabledWhenValidating = false, testId, } = props const activePage = getActivePageFrom(children) + const lastPage = isLastPage(page) const penultimate = isLastPage(page + 1) diff --git a/src/components/forms/GnoForm/index.jsx b/src/components/forms/GnoForm/index.jsx index 5adb9c23..d3d690db 100644 --- a/src/components/forms/GnoForm/index.jsx +++ b/src/components/forms/GnoForm/index.jsx @@ -36,7 +36,6 @@ const GnoForm = ({ render={({ handleSubmit, ...rest }) => (
{children(rest.submitting, rest.validating, rest, rest.form.mutators)} - {console.log({ rest })}
)} /> diff --git a/src/routes/open/components/SafeOwnersConfirmationsForm/index.jsx b/src/routes/open/components/SafeOwnersConfirmationsForm/index.jsx index ca168489..3b93fa5e 100644 --- a/src/routes/open/components/SafeOwnersConfirmationsForm/index.jsx +++ b/src/routes/open/components/SafeOwnersConfirmationsForm/index.jsx @@ -16,7 +16,10 @@ import Row from '~/components/layout/Row' import Img from '~/components/layout/Img' import Col from '~/components/layout/Col' import { - FIELD_CONFIRMATIONS, getOwnerNameBy, getOwnerAddressBy, getNumOwnersFrom, + FIELD_CONFIRMATIONS, + getOwnerNameBy, + getOwnerAddressBy, + getNumOwnersFrom, } from '~/routes/open/components/fields' import Paragraph from '~/components/layout/Paragraph' import OpenPaper from '~/components/Stepper/OpenPaper' @@ -30,6 +33,7 @@ type Props = { classes: Object, otherAccounts: string[], errors: Object, + form: Object, values: Object, updateInitialProps: (initialValues: Object) => void, } @@ -66,13 +70,16 @@ const SafeOwners = (props: Props) => { const validOwners = getNumOwnersFrom(values) const onRemoveRow = (index: number) => () => { - const initialValues = calculateValuesAfterRemoving(index, numOwners, values) - console.log({ initialValues }) - updateInitialProps(initialValues) + if (numOwners === 2) { + const { form } = props + form.reset() + } else { + const initialValues = calculateValuesAfterRemoving(index, numOwners, values) + updateInitialProps(initialValues) + } setNumOwners(numOwners - 1) } - console.log('values in form', { values }) const onAddOwner = () => { setNumOwners(numOwners + 1) @@ -166,7 +173,7 @@ const SafeOwners = (props: Props) => { {' '} {validOwners} {' '} - owner(s) +owner(s) @@ -177,16 +184,16 @@ const SafeOwners = (props: Props) => { const SafeOwnersForm = withStyles(styles)(SafeOwners) -const SafeOwnersPage = ({ updateInitialProps }: Object) => (controls: React.Node, { values, errors }: Object) => ( +const SafeOwnersPage = ({ updateInitialProps }: Object) => (controls: React.Node, { values, errors, form }: Object) => ( - {console.log('vals one level up', values)} )