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