in email step, use remote validation

This commit is contained in:
Ben Wheeler 2019-08-25 11:31:07 -04:00
parent 020231bb02
commit d6e5637dbe

View file

@ -4,9 +4,9 @@ const React = require('react');
const PropTypes = require('prop-types'); const PropTypes = require('prop-types');
import {Formik} from 'formik'; import {Formik} from 'formik';
const {injectIntl, intlShape} = require('react-intl'); const {injectIntl, intlShape} = require('react-intl');
const emailValidator = require('email-validator');
const FormattedMessage = require('react-intl').FormattedMessage; const FormattedMessage = require('react-intl').FormattedMessage;
const validate = require('../../lib/validate');
const JoinFlowStep = require('./join-flow-step.jsx'); const JoinFlowStep = require('./join-flow-step.jsx');
const FormikInput = require('../../components/formik-forms/formik-input.jsx'); const FormikInput = require('../../components/formik-forms/formik-input.jsx');
const FormikCheckbox = require('../../components/formik-forms/formik-checkbox.jsx'); const FormikCheckbox = require('../../components/formik-forms/formik-checkbox.jsx');
@ -75,11 +75,16 @@ class EmailStep extends React.Component {
} }
validateEmail (email) { validateEmail (email) {
if (!email) return this.props.intl.formatMessage({id: 'general.required'}); if (!email) return this.props.intl.formatMessage({id: 'general.required'});
const isValidLocally = emailValidator.validate(email); const localResult = validate.validateEmailLocally(email);
if (isValidLocally) { if (!localResult.valid) return this.props.intl.formatMessage({id: localResult.errMsgId});
return null; // TODO: validate email address remotely return validate.validateEmailRemotely(email).then(
remoteResult => {
if (remoteResult.valid === true) {
return null;
} }
return this.props.intl.formatMessage({id: 'registration.validationEmailInvalid'}); return this.props.intl.formatMessage({id: remoteResult.errMsgId});
}
);
} }
validateForm () { validateForm () {
return {}; return {};