From ce5558f8e2627cbb5ecc21494c7d2824ab0bff26 Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Fri, 30 Aug 2019 16:20:26 -0400 Subject: [PATCH] refactor advance step and register functions --- src/components/join-flow/join-flow.jsx | 38 +++++++++++--------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/components/join-flow/join-flow.jsx b/src/components/join-flow/join-flow.jsx index 3efb29b09..a3710b638 100644 --- a/src/components/join-flow/join-flow.jsx +++ b/src/components/join-flow/join-flow.jsx @@ -26,8 +26,8 @@ class JoinFlow extends React.Component { super(props); bindAll(this, [ 'handleAdvanceStep', - 'handleRegister', - 'handleResetForm' + 'handlePrepareToRegister', + 'handleSubmitRegistration' ]); this.state = { formData: {}, @@ -36,7 +36,16 @@ class JoinFlow extends React.Component { waiting: false }; } - handleRegister (formData) { + handlePrepareToRegister (newFormData) { + newFormData = newFormData || {}; + const newState = { + formData: defaults({}, newFormData, this.state.formData) + }; + this.setState(newState, () => { + this.handleSubmitRegistration(this.state.formData); + }); + } + handleSubmitRegistration (formData) { this.setState({waiting: true}, () => { api({ host: '', @@ -104,24 +113,9 @@ class JoinFlow extends React.Component { } handleAdvanceStep (newFormData) { newFormData = newFormData || {}; - const newState = { - formData: defaults({}, newFormData, this.state.formData) - }; - // for the first 4 steps, automatically advance to next step. - // but for email step, we need to submit registration and wait. - const shouldAdvance = (this.state.step < 4); - const shouldRegister = (this.state.step === 4); - if (shouldAdvance) newState.step = this.state.step + 1; - this.setState(newState, () => { - if (shouldRegister) this.handleRegister(this.state.formData); - }); - } - handleResetForm () { this.setState({ - formData: {}, - registrationError: null, - step: 0, - waiting: false + formData: defaults({}, newFormData, this.state.formData), + step: this.state.step + 1 }); } render () { @@ -131,7 +125,7 @@ class JoinFlow extends React.Component { this.handleRegister(this.state.formData)} + onTryAgain={() => this.handleSubmitRegistration(this.state.formData)} /* eslint-enable react/jsx-no-bind */ /> ) : ( @@ -142,7 +136,7 @@ class JoinFlow extends React.Component {