Commit f2a3dfda authored by seotts's avatar seotts

Revert "Revert "Use formik for feedback form""

This reverts commit c22c2c96.
parent 037f91e7
...@@ -10,8 +10,8 @@ const Button = require('../../forms/button.jsx'); ...@@ -10,8 +10,8 @@ const Button = require('../../forms/button.jsx');
const Progression = require('../../progression/progression.jsx'); const Progression = require('../../progression/progression.jsx');
const FlexRow = require('../../flex-row/flex-row.jsx'); const FlexRow = require('../../flex-row/flex-row.jsx');
const MuteStep = require('./mute-step.jsx'); const MuteStep = require('./mute-step.jsx');
const Formsy = require('formsy-react').default; import {Formik} from 'formik';
const InplaceInput = require('../../../components/forms/inplace-input.jsx'); const FormikInput = require('../../../components/formik-forms/formik-input.jsx');
const classNames = require('classnames'); const classNames = require('classnames');
require('./modal.scss'); require('./modal.scss');
...@@ -23,7 +23,7 @@ const steps = { ...@@ -23,7 +23,7 @@ const steps = {
FEEDBACK_SENT: 4 FEEDBACK_SENT: 4
}; };
const onUpdate = update => update; const MAX_FEEDBACK_LENGTH = 500;
class MuteModal extends React.Component { class MuteModal extends React.Component {
constructor (props) { constructor (props) {
...@@ -33,7 +33,9 @@ class MuteModal extends React.Component { ...@@ -33,7 +33,9 @@ class MuteModal extends React.Component {
'handlePrevious', 'handlePrevious',
'handleGoToFeedback', 'handleGoToFeedback',
'handleFeedbackInput', 'handleFeedbackInput',
'handleFeedbackSubmit' 'handleFeedbackSubmit',
'handleSetFeedbackRef',
'validateFeedback'
]); ]);
this.numSteps = 2; this.numSteps = 2;
if (this.props.showWarning) { if (this.props.showWarning) {
...@@ -63,18 +65,36 @@ class MuteModal extends React.Component { ...@@ -63,18 +65,36 @@ class MuteModal extends React.Component {
} }
handleFeedbackSubmit () { handleFeedbackSubmit () {
const noError = !this.validateFeedback(this.state.feedback);
if (noError) {
/* eslint-disable no-console */
console.log(this.state.feedback); console.log(this.state.feedback);
/* eslint-enable no-console */
this.setState({ this.setState({
step: steps.FEEDBACK_SENT step: steps.FEEDBACK_SENT
}); });
} }
}
handleFeedbackInput (event) { handleFeedbackInput (feedback) {
this.setState({ this.setState({
feedback: event.target.value, feedback: feedback
}); });
} }
handleSetFeedbackRef (feedbackInputRef) {
this.feedbackInput = feedbackInputRef;
}
validateFeedback (feedback) {
if (feedback.length === 0) {
return 'Can\'t be empty';
}
return null;
}
render () { render () {
const finalStep = this.showWarning ? steps.BAN_WARNING : steps.MUTE_INFO; const finalStep = this.showWarning ? steps.BAN_WARNING : steps.MUTE_INFO;
...@@ -155,19 +175,53 @@ class MuteModal extends React.Component { ...@@ -155,19 +175,53 @@ class MuteModal extends React.Component {
<p className="feedback-text"> <p className="feedback-text">
<FormattedMessage id="comments.muted.mistakeInstructions" /> <FormattedMessage id="comments.muted.mistakeInstructions" />
</p> </p>
<Formsy className="full-width-form"> <Formik
<InplaceInput initialValues={{
className={classNames('compose-feedback', feedback: ''
this.state.feedback.length > 0 ? }}
'compose-valid' : 'compose-invalid')} validate={this.validateFeedback}
handleUpdate={onUpdate} validateOnBlur={false}
name="compose-feedback" validateOnChange={false}
rows="5" >
type="textarea" {props => {
value={this.state.feedback} const {
onInput={this.handleFeedbackInput} errors,
setFieldError,
setFieldTouched,
setFieldValue,
validateField
} = props;
return (
<FormikInput
autoCapitalize="off"
autoComplete="off"
autoCorrect="off"
className={classNames(
'compose-feedback',
)}
component="textarea"
error={errors.feedback}
id="feedback"
maxLength={MAX_FEEDBACK_LENGTH}
name="feedback"
rows={5}
type="text"
validate={this.validateFeedback}
validationClassName="validation-full-width-input"
/* eslint-disable react/jsx-no-bind */
onBlur={() => 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}
/> />
</Formsy> );
}}
</Formik>
<div className="character-limit"> <div className="character-limit">
<FormattedMessage id="comments.muted.characterLimit" /> <FormattedMessage id="comments.muted.characterLimit" />
</div> </div>
......
...@@ -87,14 +87,24 @@ ...@@ -87,14 +87,24 @@
.feedback-text { .feedback-text {
text-align: center; text-align: center;
max-width: 360px;
} }
.full-width-form { textarea, .row-with-tooltip {
height: 180px; height: 180px;
width: 100%; width: 100%;
} }
textarea {
padding: 16px;
}
.character-limit { .character-limit {
font-size: .75rem; font-size: .75rem;
} }
.validation-message {
top: 30%;
margin-left: 4rem;
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment