Add input validation component to react
[MAILPOET-1809]
This commit is contained in:
@@ -126,6 +126,7 @@ tr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.mailpoet_method_selection_step {
|
.mailpoet_method_selection_step {
|
||||||
|
align-items: flex-start;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { HashRouter, Switch, Route, Redirect } from 'react-router-dom';
|
import {
|
||||||
|
HashRouter, Switch, Route, Redirect,
|
||||||
|
} from 'react-router-dom';
|
||||||
|
|
||||||
import StepMethodSelection from './import/step_method_selection.jsx';
|
import StepMethodSelection from './import/step_method_selection.jsx';
|
||||||
|
import StepInputValidation from './import/step_input_validation.jsx';
|
||||||
|
|
||||||
const container = document.getElementById('import_container');
|
const container = document.getElementById('import_container');
|
||||||
|
|
||||||
@@ -12,6 +15,7 @@ const ImportSubscribers = () => {
|
|||||||
<HashRouter>
|
<HashRouter>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path="/step_method_selection" render={props => <StepMethodSelection {...props} setStepMethodSelection={setStepMethodSelection} />} />
|
<Route path="/step_method_selection" render={props => <StepMethodSelection {...props} setStepMethodSelection={setStepMethodSelection} />} />
|
||||||
|
<Route path="/step_input_validation" render={props => <StepInputValidation {...props} stepMethodSelection={stepMethodSelection} />} />
|
||||||
<Route path="*" render={() => <Redirect to="/step_method_selection" />} />
|
<Route path="*" render={() => <Redirect to="/step_method_selection" />} />
|
||||||
</Switch>
|
</Switch>
|
||||||
</HashRouter>
|
</HashRouter>
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
import { withRouter } from 'react-router-dom';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import ReactStringReplace from 'react-string-replace';
|
import ReactStringReplace from 'react-string-replace';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
@@ -48,6 +49,12 @@ class StepInputValidation extends Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
if (typeof (this.props.stepMethodSelection) === 'undefined') {
|
||||||
|
this.props.history.replace('step_method_selection');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isFormValid() {
|
isFormValid() {
|
||||||
return this.state.subscribersAgreed
|
return this.state.subscribersAgreed
|
||||||
&& this.state.sentOnceLastYear
|
&& this.state.sentOnceLastYear
|
||||||
@@ -112,8 +119,8 @@ class StepInputValidation extends Component {
|
|||||||
</p>
|
</p>
|
||||||
<PreviousNextStepButtons
|
<PreviousNextStepButtons
|
||||||
canGoNext={this.isFormValid()}
|
canGoNext={this.isFormValid()}
|
||||||
onPreviousAction={() => this.props.navigate('step_method_selection', { trigger: true })}
|
onPreviousAction={() => this.props.history.push('step_method_selection')}
|
||||||
onNextAction={() => this.props.navigate('step_data_manipulation', { trigger: true })}
|
onNextAction={() => this.props.history.push('step_data_manipulation')}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -121,7 +128,22 @@ class StepInputValidation extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StepInputValidation.propTypes = {
|
StepInputValidation.propTypes = {
|
||||||
navigate: PropTypes.func.isRequired,
|
history: PropTypes.shape({
|
||||||
|
push: PropTypes.func.isRequired,
|
||||||
|
replace: PropTypes.func.isRequired,
|
||||||
|
}).isRequired,
|
||||||
|
stepMethodSelection: PropTypes.shape({
|
||||||
|
duplicate: PropTypes.arrayOf(PropTypes.string),
|
||||||
|
header: PropTypes.arrayOf(PropTypes.string),
|
||||||
|
invalid: PropTypes.arrayOf(PropTypes.string),
|
||||||
|
role: PropTypes.arrayOf(PropTypes.string),
|
||||||
|
subscribersCount: PropTypes.number,
|
||||||
|
subscribers: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.string)),
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default StepInputValidation;
|
StepInputValidation.defaultProps = {
|
||||||
|
stepMethodSelection: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default withRouter(StepInputValidation);
|
||||||
|
Reference in New Issue
Block a user