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,20 +137,24 @@ class GnoStepper extends React.PureComponent<Props, State> {
validation={this.validate} validation={this.validate}
render={activePage} render={activePage}
> >
{(submitting: boolean) => ( {(submitting: boolean, validating: boolean) => {
<Row align="end" margin="lg" grow> const disabled = disabledWhenValidating ? submitting || validating : submitting
<Col xs={12} center="xs">
<Controls return (
submitting={submitting} <Row align="end" margin="lg" grow>
finishedTx={finishedTransaction} <Col xs={12} center="xs">
finishedButton={finished} <Controls
onPrevious={this.previous} disabled={disabled}
firstPage={page === 0} finishedTx={finishedTransaction}
lastPage={isLastPage} finishedButton={finished}
/> onPrevious={this.previous}
</Col> firstPage={page === 0}
</Row> lastPage={isLastPage}
)} />
</Col>
</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 }