import React, { Component, PropTypes } from 'react'; import { FormattedMessage as Message } from 'react-intl'; import { Link } from 'react-router'; import classNames from 'classnames'; import Helmet from 'react-helmet'; import { Motion, spring } from 'react-motion'; import { Input, Button, Form, FormModel } from 'components/ui/form'; import styles from 'components/profile/profileForm.scss'; import helpLinks from 'components/auth/helpLinks.scss'; import MeasureHeight from 'components/MeasureHeight'; import changeEmail from './changeEmail.scss'; import messages from './ChangeEmail.messages'; const STEPS_TOTAL = 3; // TODO: disable code field, if the code was passed through url export default class ChangeEmail extends Component { static displayName = 'ChangeEmail'; static propTypes = { email: PropTypes.string.isRequired, form: PropTypes.instanceOf(FormModel), onChange: PropTypes.func.isRequired, onSubmit: PropTypes.func.isRequired }; static get defaultProps() { return { form: new FormModel() }; } state = { activeStep: 0 }; render() { const {form} = this.props; const {activeStep} = this.state; return (
{(pageTitle) => (

{pageTitle}

)}

{(new Array(STEPS_TOTAL)).fill(0).map((_, step) => (
))}
{this.renderStepForms()}
{this.isLastStep() ? null : ( )}
); } renderStepForms() { const {form, email} = this.props; const {activeStep} = this.state; const activeStepHeight = this.state[`step${activeStep}Height`] || 0; // a hack to disable height animation on first render const isHeightMeasured = this.isHeightMeasured; this.isHeightMeasured = isHeightMeasured || activeStepHeight > 0; return ( {(interpolatingStyle) => (

{email}

{email}) }} />

{form.value('newEmail')}) }} />

)}
); } onStepMeasure(step) { return (height) => this.setState({ [`step${step}Height`]: height }); } onSwitchStep = (event) => { event.preventDefault(); const {activeStep} = this.state; const nextStep = activeStep + 1; if (nextStep < STEPS_TOTAL) { this.setState({ activeStep: nextStep }); } }; isLastStep() { return this.state.activeStep + 1 === STEPS_TOTAL; } onUsernameChange = (event) => { this.props.onChange(event.target.value); }; onFormSubmit = () => { this.props.onSubmit(this.props.form); }; }