2016-05-02 23:02:03 +05:30
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
|
|
|
import ChangeEmail from 'components/profile/changeEmail/ChangeEmail';
|
|
|
|
|
2016-05-22 13:23:40 +05:30
|
|
|
import accounts from 'services/api/accounts';
|
|
|
|
|
2016-05-22 20:26:39 +05:30
|
|
|
class ChangeEmailPage extends Component {
|
|
|
|
static displayName = 'ChangeEmailPage';
|
2016-05-02 23:02:03 +05:30
|
|
|
|
|
|
|
static propTypes = {
|
2016-05-20 10:44:14 +05:30
|
|
|
email: PropTypes.string.isRequired,
|
|
|
|
params: PropTypes.shape({
|
|
|
|
step: PropTypes.oneOf(['step1', 'step2', 'step3']),
|
|
|
|
code: PropTypes.string
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.shape({
|
|
|
|
push: PropTypes.func
|
2016-05-22 13:23:40 +05:30
|
|
|
}).isRequired,
|
|
|
|
onSubmit: PropTypes.func.isRequired,
|
|
|
|
goToProfile: PropTypes.func.isRequired
|
2016-05-02 23:02:03 +05:30
|
|
|
};
|
|
|
|
|
2016-05-20 10:44:14 +05:30
|
|
|
componentWillMount() {
|
|
|
|
const step = this.props.params.step;
|
|
|
|
|
|
|
|
if (step && !/^step\d$/.test(step)) {
|
|
|
|
// wrong param value
|
|
|
|
// TODO: probably we should decide with something better here
|
|
|
|
this.context.router.push('/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-02 23:02:03 +05:30
|
|
|
render() {
|
2016-05-22 13:23:40 +05:30
|
|
|
const {params: {step = 'step1', code}} = this.props;
|
2016-05-20 10:44:14 +05:30
|
|
|
|
2016-05-02 23:02:03 +05:30
|
|
|
return (
|
2016-05-22 13:23:40 +05:30
|
|
|
<ChangeEmail
|
2016-05-02 23:02:03 +05:30
|
|
|
onSubmit={this.onSubmit}
|
|
|
|
email={this.props.email}
|
2016-05-22 13:23:40 +05:30
|
|
|
step={step.slice(-1) * 1 - 1}
|
2016-05-20 10:44:14 +05:30
|
|
|
onChangeStep={this.onChangeStep}
|
|
|
|
code={code}
|
2016-05-02 23:02:03 +05:30
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-05-20 10:44:14 +05:30
|
|
|
onChangeStep = (step) => {
|
|
|
|
this.context.router.push(`/profile/change-email/step${++step}`);
|
|
|
|
};
|
|
|
|
|
2016-05-22 13:23:40 +05:30
|
|
|
onSubmit = (step, form) => {
|
|
|
|
return this.context.onSubmit({
|
|
|
|
form,
|
|
|
|
sendData: () => {
|
|
|
|
const data = form.serialize();
|
|
|
|
|
|
|
|
switch (step) {
|
|
|
|
case 0:
|
|
|
|
return accounts.requestEmailChange();
|
|
|
|
case 1:
|
|
|
|
return accounts.setNewEmail(data);
|
|
|
|
case 2:
|
|
|
|
return accounts.confirmNewEmail(data);
|
|
|
|
default:
|
|
|
|
throw new Error(`Unsupported step ${step}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).then(() => {
|
|
|
|
step > 1 && this.context.goToProfile();
|
|
|
|
});
|
2016-05-02 23:02:03 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
export default connect((state) => ({
|
|
|
|
email: state.user.email
|
|
|
|
}), {
|
2016-05-22 20:26:39 +05:30
|
|
|
})(ChangeEmailPage);
|