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, steps, children, classes, disabledWhenValidating = false, testId,
} = props } = props
const activePage = getActivePageFrom(children) const activePage = getActivePageFrom(children)
const lastPage = isLastPage(page) const lastPage = isLastPage(page)
const penultimate = isLastPage(page + 1) const penultimate = isLastPage(page + 1)

View File

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

View File

@ -16,7 +16,10 @@ import Row from '~/components/layout/Row'
import Img from '~/components/layout/Img' import Img from '~/components/layout/Img'
import Col from '~/components/layout/Col' import Col from '~/components/layout/Col'
import { import {
FIELD_CONFIRMATIONS, getOwnerNameBy, getOwnerAddressBy, getNumOwnersFrom, FIELD_CONFIRMATIONS,
getOwnerNameBy,
getOwnerAddressBy,
getNumOwnersFrom,
} from '~/routes/open/components/fields' } from '~/routes/open/components/fields'
import Paragraph from '~/components/layout/Paragraph' import Paragraph from '~/components/layout/Paragraph'
import OpenPaper from '~/components/Stepper/OpenPaper' import OpenPaper from '~/components/Stepper/OpenPaper'
@ -30,6 +33,7 @@ type Props = {
classes: Object, classes: Object,
otherAccounts: string[], otherAccounts: string[],
errors: Object, errors: Object,
form: Object,
values: Object, values: Object,
updateInitialProps: (initialValues: Object) => void, updateInitialProps: (initialValues: Object) => void,
} }
@ -66,13 +70,16 @@ const SafeOwners = (props: Props) => {
const validOwners = getNumOwnersFrom(values) const validOwners = getNumOwnersFrom(values)
const onRemoveRow = (index: number) => () => { const onRemoveRow = (index: number) => () => {
const initialValues = calculateValuesAfterRemoving(index, numOwners, values) if (numOwners === 2) {
console.log({ initialValues }) const { form } = props
updateInitialProps(initialValues) form.reset()
} else {
const initialValues = calculateValuesAfterRemoving(index, numOwners, values)
updateInitialProps(initialValues)
}
setNumOwners(numOwners - 1) setNumOwners(numOwners - 1)
} }
console.log('values in form', { values })
const onAddOwner = () => { const onAddOwner = () => {
setNumOwners(numOwners + 1) setNumOwners(numOwners + 1)
@ -166,7 +173,7 @@ const SafeOwners = (props: Props) => {
{' '} {' '}
{validOwners} {validOwners}
{' '} {' '}
owner(s) owner(s)
</Paragraph> </Paragraph>
</Col> </Col>
</Row> </Row>
@ -177,16 +184,16 @@ const SafeOwners = (props: Props) => {
const SafeOwnersForm = withStyles(styles)(SafeOwners) 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> <React.Fragment>
<OpenPaper controls={controls} padding={false}> <OpenPaper controls={controls} padding={false}>
<SafeOwnersForm <SafeOwnersForm
otherAccounts={getAccountsFrom(values)} otherAccounts={getAccountsFrom(values)}
errors={errors} errors={errors}
form={form}
updateInitialProps={updateInitialProps} updateInitialProps={updateInitialProps}
values={values} values={values}
/> />
{console.log('vals one level up', values)}
</OpenPaper> </OpenPaper>
</React.Fragment> </React.Fragment>
) )