WA-232 Disabling stepper controls when validating if prop is set

This commit is contained in:
apanizo 2018-07-25 11:11:59 +02:00
parent 1ccb735494
commit 3ea1446df5
3 changed files with 29 additions and 23 deletions

View File

@ -6,16 +6,16 @@ type ControlProps = {
next: string, next: string,
onPrevious: () => void, onPrevious: () => void,
firstPage: boolean, firstPage: boolean,
submitting: boolean, disabled: boolean,
} }
const ControlButtons = ({ const ControlButtons = ({
next, firstPage, onPrevious, submitting, next, firstPage, onPrevious, disabled,
}: ControlProps) => ( }: ControlProps) => (
<React.Fragment> <React.Fragment>
<Button <Button
type="button" type="button"
disabled={firstPage || submitting} disabled={firstPage || disabled}
onClick={onPrevious} onClick={onPrevious}
> >
Back Back
@ -24,7 +24,7 @@ const ControlButtons = ({
variant="raised" variant="raised"
color="primary" color="primary"
type="submit" type="submit"
disabled={submitting} disabled={disabled}
> >
{next} {next}
</Button> </Button>
@ -37,16 +37,16 @@ type Props = {
onPrevious: () => void, onPrevious: () => void,
firstPage: boolean, firstPage: boolean,
lastPage: boolean, lastPage: boolean,
submitting: boolean, disabled: boolean,
} }
const Controls = ({ const Controls = ({
finishedTx, finishedButton, onPrevious, firstPage, lastPage, submitting, finishedTx, finishedButton, onPrevious, firstPage, lastPage, disabled,
}: Props) => ( }: Props) => (
finishedTx finishedTx
? <React.Fragment>{finishedButton}</React.Fragment> ? <React.Fragment>{finishedButton}</React.Fragment>
: <ControlButtons : <ControlButtons
submitting={submitting} disabled={disabled}
next={lastPage ? 'Finish' : 'Next'} next={lastPage ? 'Finish' : 'Next'}
firstPage={firstPage} firstPage={firstPage}
onPrevious={onPrevious} onPrevious={onPrevious}

View File

@ -13,6 +13,7 @@ import Controls from './Controls'
export { default as Step } from './Step' export { default as Step } from './Step'
type Props = { type Props = {
disabledWhenValidating?: boolean,
classes: Object, classes: Object,
steps: string[], steps: string[],
finishedTransaction: boolean, finishedTransaction: boolean,
@ -100,7 +101,7 @@ class GnoStepper extends React.PureComponent<Props, State> {
page: Math.max(state.page - 1, 0), page: Math.max(state.page - 1, 0),
})) }))
handleSubmit = (values: Object) => { handleSubmit = async (values: Object) => {
const { children, onSubmit } = this.props const { children, onSubmit } = this.props
const { page } = this.state const { page } = this.state
const isLastPage = page === React.Children.count(children) - 1 const isLastPage = page === React.Children.count(children) - 1
@ -113,7 +114,7 @@ class GnoStepper extends React.PureComponent<Props, State> {
render() { render() {
const { const {
steps, children, finishedTransaction, finishedButton, classes, steps, children, finishedTransaction, finishedButton, classes, disabledWhenValidating = false,
} = this.props } = this.props
const { page, values } = this.state const { page, values } = this.state
const activePage = this.getActivePageFrom(children) const activePage = this.getActivePageFrom(children)
@ -136,11 +137,14 @@ class GnoStepper extends React.PureComponent<Props, State> {
validation={this.validate} validation={this.validate}
render={activePage} render={activePage}
> >
{(submitting: boolean) => ( {(submitting: boolean, validating: boolean) => {
const disabled = disabledWhenValidating ? submitting || validating : submitting
return (
<Row align="end" margin="lg" grow> <Row align="end" margin="lg" grow>
<Col xs={12} center="xs"> <Col xs={12} center="xs">
<Controls <Controls
submitting={submitting} disabled={disabled}
finishedTx={finishedTransaction} finishedTx={finishedTransaction}
finishedButton={finished} finishedButton={finished}
onPrevious={this.previous} onPrevious={this.previous}
@ -149,7 +153,8 @@ class GnoStepper extends React.PureComponent<Props, State> {
/> />
</Col> </Col>
</Row> </Row>
)} )
}}
</GnoForm> </GnoForm>
</React.Fragment> </React.Fragment>
) )

View File

@ -92,6 +92,7 @@ class AddToken extends React.Component<Props, State> {
onSubmit={this.onAddToken} onSubmit={this.onAddToken}
steps={steps} steps={steps}
onReset={this.onReset} onReset={this.onReset}
disabledWhenValidating
> >
<Stepper.Page addresses={tokens} prepareNextInitialProps={this.fetchInitialPropsSecondPage}> <Stepper.Page addresses={tokens} prepareNextInitialProps={this.fetchInitialPropsSecondPage}>
{ FirstPage } { FirstPage }