From 3ea1446df5b4d408e4daf061679b1875fc7849b1 Mon Sep 17 00:00:00 2001 From: apanizo Date: Wed, 25 Jul 2018 11:11:59 +0200 Subject: [PATCH] WA-232 Disabling stepper controls when validating if prop is set --- src/components/Stepper/Controls/index.jsx | 14 +++---- src/components/Stepper/index.jsx | 37 +++++++++++-------- .../tokens/component/AddToken/index.jsx | 1 + 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/components/Stepper/Controls/index.jsx b/src/components/Stepper/Controls/index.jsx index ebcbd2cf..fd96b62d 100644 --- a/src/components/Stepper/Controls/index.jsx +++ b/src/components/Stepper/Controls/index.jsx @@ -6,16 +6,16 @@ type ControlProps = { next: string, onPrevious: () => void, firstPage: boolean, - submitting: boolean, + disabled: boolean, } const ControlButtons = ({ - next, firstPage, onPrevious, submitting, + next, firstPage, onPrevious, disabled, }: ControlProps) => ( @@ -37,16 +37,16 @@ type Props = { onPrevious: () => void, firstPage: boolean, lastPage: boolean, - submitting: boolean, + disabled: boolean, } const Controls = ({ - finishedTx, finishedButton, onPrevious, firstPage, lastPage, submitting, + finishedTx, finishedButton, onPrevious, firstPage, lastPage, disabled, }: Props) => ( finishedTx ? {finishedButton} : { page: Math.max(state.page - 1, 0), })) - handleSubmit = (values: Object) => { + handleSubmit = async (values: Object) => { const { children, onSubmit } = this.props const { page } = this.state const isLastPage = page === React.Children.count(children) - 1 @@ -113,7 +114,7 @@ class GnoStepper extends React.PureComponent { render() { const { - steps, children, finishedTransaction, finishedButton, classes, + steps, children, finishedTransaction, finishedButton, classes, disabledWhenValidating = false, } = this.props const { page, values } = this.state const activePage = this.getActivePageFrom(children) @@ -136,20 +137,24 @@ class GnoStepper extends React.PureComponent { validation={this.validate} render={activePage} > - {(submitting: boolean) => ( - - - - - - )} + {(submitting: boolean, validating: boolean) => { + const disabled = disabledWhenValidating ? submitting || validating : submitting + + return ( + + + + + + ) + }} ) diff --git a/src/routes/tokens/component/AddToken/index.jsx b/src/routes/tokens/component/AddToken/index.jsx index a6d9ea86..981b68fd 100644 --- a/src/routes/tokens/component/AddToken/index.jsx +++ b/src/routes/tokens/component/AddToken/index.jsx @@ -92,6 +92,7 @@ class AddToken extends React.Component { onSubmit={this.onAddToken} steps={steps} onReset={this.onReset} + disabledWhenValidating > { FirstPage }