reset form when the only owner left is initial one
This commit is contained in:
parent
f9c67171a8
commit
ca13a00d19
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -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) => () => {
|
||||||
|
if (numOwners === 2) {
|
||||||
|
const { form } = props
|
||||||
|
form.reset()
|
||||||
|
} else {
|
||||||
const initialValues = calculateValuesAfterRemoving(index, numOwners, values)
|
const initialValues = calculateValuesAfterRemoving(index, numOwners, values)
|
||||||
console.log({ initialValues })
|
|
||||||
updateInitialProps(initialValues)
|
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>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue