2019-07-29 22:29:04 -04:00
|
|
|
const bindAll = require('lodash.bindall');
|
2019-08-01 15:40:46 -04:00
|
|
|
const classNames = require('classnames');
|
2019-07-29 22:29:04 -04:00
|
|
|
const React = require('react');
|
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
import {Formik} from 'formik';
|
|
|
|
const {injectIntl, intlShape} = require('react-intl');
|
2019-08-06 20:22:58 -04:00
|
|
|
const emailValidator = require('email-validator');
|
2019-07-29 22:29:04 -04:00
|
|
|
|
|
|
|
const JoinFlowStep = require('./join-flow-step.jsx');
|
2019-08-01 15:40:46 -04:00
|
|
|
const FormikInput = require('../../components/formik-forms/formik-input.jsx');
|
2019-07-29 22:29:04 -04:00
|
|
|
|
|
|
|
require('./join-flow-steps.scss');
|
|
|
|
|
|
|
|
class EmailStep extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
bindAll(this, [
|
|
|
|
'handleValidSubmit',
|
2019-08-01 15:40:46 -04:00
|
|
|
'validateEmailIfPresent',
|
2019-07-29 22:29:04 -04:00
|
|
|
'validateForm'
|
|
|
|
]);
|
|
|
|
}
|
2019-08-01 15:40:46 -04:00
|
|
|
validateEmailIfPresent (email) {
|
|
|
|
if (!email) return null; // skip validation if email is blank; null indicates valid
|
2019-08-08 00:22:15 -04:00
|
|
|
const isValidLocally = emailValidator.validate(email);
|
|
|
|
if (isValidLocally) {
|
2019-08-01 15:40:46 -04:00
|
|
|
return null; // TODO: validate email address remotely
|
|
|
|
}
|
|
|
|
return this.props.intl.formatMessage({id: 'registration.validationEmailInvalid'});
|
|
|
|
}
|
2019-07-29 22:29:04 -04:00
|
|
|
validateForm () {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
handleValidSubmit (formData, formikBag) {
|
|
|
|
formikBag.setSubmitting(false);
|
|
|
|
this.props.onNextStep(formData);
|
|
|
|
}
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<Formik
|
|
|
|
initialValues={{
|
|
|
|
}}
|
|
|
|
validate={this.validateForm}
|
|
|
|
validateOnBlur={false}
|
|
|
|
validateOnChange={false}
|
|
|
|
onSubmit={this.handleValidSubmit}
|
|
|
|
>
|
|
|
|
{props => {
|
|
|
|
const {
|
2019-08-01 15:40:46 -04:00
|
|
|
errors,
|
2019-07-29 22:29:04 -04:00
|
|
|
handleSubmit,
|
2019-08-01 15:40:46 -04:00
|
|
|
isSubmitting,
|
|
|
|
validateField
|
2019-07-29 22:29:04 -04:00
|
|
|
} = props;
|
|
|
|
return (
|
|
|
|
<JoinFlowStep
|
|
|
|
description={this.props.intl.formatMessage({id: 'registration.emailStepDescription'})}
|
2019-08-10 23:18:33 -04:00
|
|
|
footerMessage={this.props.intl.formatMessage({id: 'registration.acceptTermsOfService'})}
|
2019-07-29 22:29:04 -04:00
|
|
|
headerImgSrc="/images/hoc/getting-started.jpg"
|
2019-08-01 15:40:46 -04:00
|
|
|
innerContentClassName="modal-inner-content-email"
|
2019-08-10 23:18:33 -04:00
|
|
|
nextButton={this.props.intl.formatMessage({id: 'registration.createAccount'})}
|
2019-07-29 22:29:04 -04:00
|
|
|
title={this.props.intl.formatMessage({id: 'registration.emailStepTitle'})}
|
|
|
|
waiting={isSubmitting}
|
|
|
|
onSubmit={handleSubmit}
|
2019-08-01 15:40:46 -04:00
|
|
|
>
|
|
|
|
<FormikInput
|
|
|
|
className={classNames(
|
|
|
|
'join-flow-input',
|
|
|
|
'join-flow-input-tall',
|
|
|
|
{fail: errors.email}
|
|
|
|
)}
|
|
|
|
error={errors.email}
|
|
|
|
id="email"
|
|
|
|
name="email"
|
2019-08-08 11:19:18 -04:00
|
|
|
placeholder={this.props.intl.formatMessage({id: 'general.emailAddress'})}
|
2019-08-01 15:40:46 -04:00
|
|
|
validate={this.validateEmailIfPresent}
|
|
|
|
validationClassName="validation-full-width-input"
|
|
|
|
onBlur={() => validateField('email')} // eslint-disable-line react/jsx-no-bind
|
|
|
|
/>
|
|
|
|
</JoinFlowStep>
|
2019-07-29 22:29:04 -04:00
|
|
|
);
|
|
|
|
}}
|
|
|
|
</Formik>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EmailStep.propTypes = {
|
|
|
|
intl: intlShape,
|
|
|
|
onNextStep: PropTypes.func
|
|
|
|
};
|
|
|
|
|
2019-08-06 20:22:58 -04:00
|
|
|
|
2019-07-29 22:29:04 -04:00
|
|
|
module.exports = injectIntl(EmailStep);
|