2019-07-18 20:39:16 -04:00
|
|
|
const bindAll = require('lodash.bindall');
|
|
|
|
const classNames = require('classnames');
|
|
|
|
const React = require('react');
|
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
import {Formik} from 'formik';
|
|
|
|
const {injectIntl, intlShape} = require('react-intl');
|
2019-09-15 17:05:47 -04:00
|
|
|
const FormattedMessage = require('react-intl').FormattedMessage;
|
2019-07-18 20:39:16 -04:00
|
|
|
|
|
|
|
const FormikSelect = require('../../components/formik-forms/formik-select.jsx');
|
|
|
|
const JoinFlowStep = require('./join-flow-step.jsx');
|
2019-09-15 17:05:47 -04:00
|
|
|
const InfoButton = require('../info-button/info-button.jsx');
|
2019-07-18 20:39:16 -04:00
|
|
|
|
|
|
|
require('./join-flow-steps.scss');
|
|
|
|
|
|
|
|
const getBirthMonthOptions = intl => ([
|
2019-09-16 21:45:26 -04:00
|
|
|
{value: 'null', label: intl.formatMessage({id: 'general.month'}), disabled: true},
|
2019-07-18 20:39:16 -04:00
|
|
|
{value: '1', label: intl.formatMessage({id: 'general.monthJanuary'})},
|
|
|
|
{value: '2', label: intl.formatMessage({id: 'general.monthFebruary'})},
|
|
|
|
{value: '3', label: intl.formatMessage({id: 'general.monthMarch'})},
|
|
|
|
{value: '4', label: intl.formatMessage({id: 'general.monthApril'})},
|
|
|
|
{value: '5', label: intl.formatMessage({id: 'general.monthMay'})},
|
|
|
|
{value: '6', label: intl.formatMessage({id: 'general.monthJune'})},
|
|
|
|
{value: '7', label: intl.formatMessage({id: 'general.monthJuly'})},
|
|
|
|
{value: '8', label: intl.formatMessage({id: 'general.monthAugust'})},
|
|
|
|
{value: '9', label: intl.formatMessage({id: 'general.monthSeptember'})},
|
|
|
|
{value: '10', label: intl.formatMessage({id: 'general.monthOctober'})},
|
|
|
|
{value: '11', label: intl.formatMessage({id: 'general.monthNovember'})},
|
|
|
|
{value: '12', label: intl.formatMessage({id: 'general.monthDecember'})}
|
|
|
|
]);
|
|
|
|
|
|
|
|
const getBirthYearOptions = intl => {
|
|
|
|
const curYearRaw = (new Date()).getYear();
|
|
|
|
const curYear = curYearRaw + 1900;
|
|
|
|
// including both 1900 and current year, there are (curYearRaw + 1) options.
|
|
|
|
const numYearOptions = curYearRaw + 1;
|
|
|
|
const birthYearOptions = Array(numYearOptions).fill()
|
|
|
|
.map((defaultVal, i) => (
|
|
|
|
{value: String(curYear - i), label: String(curYear - i)}
|
|
|
|
));
|
2019-09-16 21:45:26 -04:00
|
|
|
birthYearOptions.unshift({ // set placeholder as first option
|
|
|
|
disabled: true,
|
2019-07-18 20:39:16 -04:00
|
|
|
value: 'null',
|
|
|
|
label: intl.formatMessage({id: 'general.year'})
|
|
|
|
});
|
|
|
|
return birthYearOptions;
|
|
|
|
};
|
|
|
|
|
|
|
|
class BirthDateStep extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
bindAll(this, [
|
|
|
|
'handleValidSubmit',
|
|
|
|
'validateForm',
|
|
|
|
'validateSelect'
|
|
|
|
]);
|
|
|
|
}
|
2019-11-04 10:47:04 -05:00
|
|
|
componentDidMount () {
|
2019-11-05 18:17:37 -05:00
|
|
|
if (this.props.sendAnalytics) {
|
|
|
|
this.props.sendAnalytics('join-birthdate');
|
|
|
|
}
|
2019-11-04 10:47:04 -05:00
|
|
|
}
|
|
|
|
|
2019-07-18 20:39:16 -04:00
|
|
|
validateSelect (selection) {
|
|
|
|
if (selection === 'null') {
|
2019-08-11 16:13:07 -04:00
|
|
|
return this.props.intl.formatMessage({id: 'general.required'});
|
2019-07-18 20:39:16 -04:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
validateForm () {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
handleValidSubmit (formData, formikBag) {
|
|
|
|
formikBag.setSubmitting(false);
|
|
|
|
this.props.onNextStep(formData);
|
|
|
|
}
|
|
|
|
render () {
|
|
|
|
const birthMonthOptions = getBirthMonthOptions(this.props.intl);
|
|
|
|
const birthYearOptions = getBirthYearOptions(this.props.intl);
|
|
|
|
return (
|
|
|
|
<Formik
|
|
|
|
initialValues={{
|
|
|
|
birth_month: 'null',
|
|
|
|
birth_year: 'null'
|
|
|
|
}}
|
|
|
|
validate={this.validateForm}
|
|
|
|
validateOnBlur={false}
|
|
|
|
validateOnChange={false}
|
|
|
|
onSubmit={this.handleValidSubmit}
|
|
|
|
>
|
|
|
|
{props => {
|
|
|
|
const {
|
|
|
|
errors,
|
|
|
|
handleSubmit,
|
2019-09-16 22:34:32 -04:00
|
|
|
isSubmitting,
|
|
|
|
setFieldError
|
2019-07-18 20:39:16 -04:00
|
|
|
} = props;
|
|
|
|
return (
|
|
|
|
<JoinFlowStep
|
2019-10-03 19:25:56 -04:00
|
|
|
headerImgClass="birthdate-step-image"
|
2019-08-16 15:05:15 -04:00
|
|
|
headerImgSrc="/images/join-flow/birthdate-header.png"
|
2019-08-17 00:52:52 -04:00
|
|
|
innerClassName="join-flow-inner-birthdate-step"
|
2019-07-26 15:54:16 -04:00
|
|
|
title={this.props.intl.formatMessage({id: 'registration.birthDateStepTitle'})}
|
2019-09-15 17:11:43 -04:00
|
|
|
titleClassName="join-flow-birthdate-title"
|
2019-07-18 20:39:16 -04:00
|
|
|
waiting={isSubmitting}
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'col-sm-9',
|
|
|
|
'row',
|
|
|
|
'birthdate-select-row'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<FormikSelect
|
|
|
|
className={classNames(
|
|
|
|
'join-flow-select',
|
|
|
|
'join-flow-select-month',
|
|
|
|
{fail: errors.birth_month}
|
|
|
|
)}
|
2019-08-20 21:56:40 -04:00
|
|
|
/* hide month (left side) error, if year (right side) error exists */
|
|
|
|
error={errors.birth_year ? null : errors.birth_month}
|
2019-07-18 20:39:16 -04:00
|
|
|
id="birth_month"
|
|
|
|
name="birth_month"
|
|
|
|
options={birthMonthOptions}
|
|
|
|
validate={this.validateSelect}
|
2019-08-20 21:56:40 -04:00
|
|
|
validationClassName={classNames(
|
2019-09-23 16:18:20 -04:00
|
|
|
'validation-birthdate',
|
2019-08-20 21:56:40 -04:00
|
|
|
'validation-birthdate-month',
|
|
|
|
'validation-left'
|
|
|
|
)}
|
2019-09-16 22:34:32 -04:00
|
|
|
/* eslint-disable react/jsx-no-bind */
|
|
|
|
onFocus={() => setFieldError('birth_month', null)}
|
|
|
|
/* eslint-enable react/jsx-no-bind */
|
2019-07-18 20:39:16 -04:00
|
|
|
/>
|
|
|
|
<FormikSelect
|
|
|
|
className={classNames(
|
|
|
|
'join-flow-select',
|
2019-08-20 21:56:40 -04:00
|
|
|
'join-flow-select-year',
|
2019-07-18 20:39:16 -04:00
|
|
|
{fail: errors.birth_year}
|
|
|
|
)}
|
|
|
|
error={errors.birth_year}
|
|
|
|
id="birth_year"
|
|
|
|
name="birth_year"
|
|
|
|
options={birthYearOptions}
|
|
|
|
validate={this.validateSelect}
|
2019-09-23 16:18:20 -04:00
|
|
|
validationClassName={classNames(
|
|
|
|
'validation-birthdate',
|
|
|
|
'validation-birthdate-year'
|
|
|
|
)}
|
2019-09-16 22:34:32 -04:00
|
|
|
/* eslint-disable react/jsx-no-bind */
|
|
|
|
onFocus={() => setFieldError('birth_year', null)}
|
|
|
|
/* eslint-enable react/jsx-no-bind */
|
2019-07-18 20:39:16 -04:00
|
|
|
/>
|
|
|
|
</div>
|
2019-09-15 21:41:05 -04:00
|
|
|
<div className="join-flow-privacy-message">
|
2019-09-15 17:05:47 -04:00
|
|
|
<FormattedMessage id="registration.private" />
|
|
|
|
<InfoButton
|
|
|
|
message={this.props.intl.formatMessage({id: 'registration.birthDateStepInfo'})}
|
|
|
|
/>
|
|
|
|
</div>
|
2019-07-18 20:39:16 -04:00
|
|
|
</JoinFlowStep>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</Formik>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BirthDateStep.propTypes = {
|
|
|
|
intl: intlShape,
|
2019-11-04 10:47:04 -05:00
|
|
|
onNextStep: PropTypes.func,
|
2019-11-05 11:54:20 -05:00
|
|
|
sendAnalytics: PropTypes.func.isRequired
|
2019-07-18 20:39:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const IntlBirthDateStep = injectIntl(BirthDateStep);
|
|
|
|
|
|
|
|
module.exports = IntlBirthDateStep;
|