mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-23 07:38:07 -05:00
in email step, use remote validation
This commit is contained in:
parent
020231bb02
commit
d6e5637dbe
1 changed files with 11 additions and 6 deletions
|
@ -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 {};
|
||||||
|
|
Loading…
Reference in a new issue