Updating SafeOwnersForm to change initial values of the form

This commit is contained in:
apanizo 2018-10-02 17:10:56 +02:00
parent f31976df87
commit ef17ca59a5
1 changed files with 28 additions and 17 deletions

View File

@ -23,6 +23,7 @@ type Props = {
classes: Object, classes: Object,
otherAccounts: string[], otherAccounts: string[],
errors: Object, errors: Object,
// updateInitialProps: () => void,
} }
type State = { type State = {
@ -68,6 +69,19 @@ class SafeOwners extends React.Component<Props, State> {
numOwners: 3, numOwners: 3,
} }
// eslint-disable-next-line
onRemoveRow = (index: number) => () => {
/*
this.props.updateInitialProps({
owner0Address: 'moeFeo',
})
*/
this.setState(state => ({
numOwners: state.numOwners - 1,
}))
}
render() { render() {
const { classes, errors, otherAccounts } = this.props const { classes, errors, otherAccounts } = this.props
const { numOwners } = this.state const { numOwners } = this.state
@ -81,12 +95,8 @@ class SafeOwners extends React.Component<Props, State> {
</Block> </Block>
<Hairline /> <Hairline />
<Row className={classes.owner}> <Row className={classes.owner}>
<Col xs={4}> <Col xs={4}>NAME</Col>
NAME <Col xs={8}>ADDRESS</Col>
</Col>
<Col xs={8}>
ADDRESS
</Col>
</Row> </Row>
<Hairline /> <Hairline />
{ [...Array(Number(numOwners))].map((x, index) => { { [...Array(Number(numOwners))].map((x, index) => {
@ -124,7 +134,7 @@ class SafeOwners extends React.Component<Props, State> {
</Col> </Col>
<Col xs={1} center="xs" middle="xs"> <Col xs={1} center="xs" middle="xs">
{ index > 0 && { index > 0 &&
<IconButton aria-label="Delete" onClick={undefined} className={classes.trash}> <IconButton aria-label="Delete" onClick={this.onRemoveRow(index)} className={classes.trash}>
<Delete /> <Delete />
</IconButton> </IconButton>
} }
@ -144,16 +154,17 @@ class SafeOwners extends React.Component<Props, State> {
const SafeOwnersForm = withStyles(styles)(SafeOwners) const SafeOwnersForm = withStyles(styles)(SafeOwners)
const SafeOwnersPage = () => (controls: React$Node, moe: Object) => { const SafeOwnersPage = ({ updateInitialProps }: Object) => (controls: React$Node, { values, errors }: Object) => (
const { values, errors } = moe <React.Fragment>
<OpenPaper controls={controls} padding={false}>
<SafeOwnersForm
otherAccounts={getAccountsFrom(values)}
errors={errors}
updateInitialProps={updateInitialProps}
/>
</OpenPaper>
</React.Fragment>
)
return (
<React.Fragment>
<OpenPaper controls={controls} padding={false}>
<SafeOwnersForm otherAccounts={getAccountsFrom(values)} errors={errors} />
</OpenPaper>
</React.Fragment>
)
}
export default SafeOwnersPage export default SafeOwnersPage