reset form when the only owner left is initial one

This commit is contained in:
mmv 2019-07-18 19:06:59 +04:00
parent f9c67171a8
commit ca13a00d19
3 changed files with 16 additions and 9 deletions

View File

@ -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)

View File

@ -36,7 +36,6 @@ const GnoForm = ({
render={({ handleSubmit, ...rest }) => (
<form onSubmit={handleSubmit} style={stylesBasedOn(padding)} data-testid={testId}>
{children(rest.submitting, rest.validating, rest, rest.form.mutators)}
{console.log({ rest })}
</form>
)}
/>

View File

@ -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)
</Paragraph>
</Col>
</Row>
@ -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) => (
<React.Fragment>
<OpenPaper controls={controls} padding={false}>
<SafeOwnersForm
otherAccounts={getAccountsFrom(values)}
errors={errors}
form={form}
updateInitialProps={updateInitialProps}
values={values}
/>
{console.log('vals one level up', values)}
</OpenPaper>
</React.Fragment>
)