diff --git a/src/components/modal/mute/modal.jsx b/src/components/modal/mute/modal.jsx index 44936168b..f9ea0918d 100644 --- a/src/components/modal/mute/modal.jsx +++ b/src/components/modal/mute/modal.jsx @@ -32,18 +32,15 @@ class MuteModal extends React.Component { 'handleNext', 'handlePrevious', 'handleGoToFeedback', - 'handleFeedbackInput', - 'handleFeedbackSubmit', 'handleSetFeedbackRef', + 'handleValidSubmit', 'validateFeedback' ]); - this.numSteps = 2; - if (this.props.showWarning) { - this.numSteps++; - } + + this.numSteps = this.props.showWarning ? steps.BAN_WARNING : steps.MUTE_INFO; + this.state = { - step: 0, - feedback: '' + step: 0 }; } handleNext () { @@ -64,22 +61,16 @@ class MuteModal extends React.Component { }); } - handleFeedbackSubmit () { - const noError = !this.validateFeedback(this.state.feedback); + // called after feedback validation passes with no errors + handleValidSubmit (formData, formikBag) { + formikBag.setSubmitting(false); // formik makes us do this ourselves - if (noError) { - /* eslint-disable no-console */ - console.log(this.state.feedback); - /* eslint-enable no-console */ - this.setState({ - step: steps.FEEDBACK_SENT - }); - } - } + /* eslint-disable no-console */ + console.log(formData.feedback); + /* eslint-enable no-console */ - handleFeedbackInput (feedback) { this.setState({ - feedback: feedback + step: steps.FEEDBACK_SENT }); } @@ -89,14 +80,24 @@ class MuteModal extends React.Component { validateFeedback (feedback) { if (feedback.length === 0) { - return 'Can\'t be empty'; + return this.props.intl.formatMessage({id: 'comments.muted.feedbackEmpty'}); } - return null; } render () { - const finalStep = this.showWarning ? steps.BAN_WARNING : steps.MUTE_INFO; + const feedbackPrompt = ( +

+ + + + )}} + /> +

+ ); return (

-

- - - - )}} - /> -

+ {this.state.step === this.numSteps ? feedbackPrompt : null}

+ {this.state.step === this.numSteps ? feedbackPrompt : null}
{props => { const { errors, + handleSubmit, setFieldError, setFieldTouched, setFieldValue, validateField } = props; return ( - validateField('feedback')} - onChange={e => { - setFieldValue('feedback', e.target.value); - setFieldTouched('feedback'); - setFieldError('feedback', null); - this.handleFeedbackInput(e.target.value); - }} - /* eslint-enable react/jsx-no-bind */ - onSetRef={this.handleSetFeedbackRef} - /> +
+ validateField('feedback')} + onChange={e => { + setFieldValue('feedback', e.target.value); + setFieldTouched('feedback'); + setFieldError('feedback', null); + }} + /* eslint-enable react/jsx-no-bind */ + onSetRef={this.handleSetFeedbackRef} + /> + ); }} @@ -242,7 +241,7 @@ class MuteModal extends React.Component { this.state.step === steps.USER_FEEDBACK ? 'feedback-nav' : 'mute-nav' )} > - {this.state.step >= finalStep ? ( + {this.state.step >= this.numSteps ? (