accounts-frontend/src/pages/profile/MultiFactorAuthPage.js

65 lines
1.5 KiB
JavaScript
Raw Normal View History

// @flow
import React, { Component } from 'react';
import PropTypes from 'prop-types';
2017-07-22 21:27:38 +05:30
import MultiFactorAuth, { MfaStep } from 'components/profile/multiFactorAuth';
2017-07-22 21:27:38 +05:30
import type { FormModel } from 'components/ui/form';
2017-07-22 21:27:38 +05:30
class MultiFactorAuthPage extends Component {
props: {
history: {
push: (string) => void
},
match: {
params: {
step?: '1'|'2'|'3'
}
}
2017-07-22 21:27:38 +05:30
};
static contextTypes = {
onSubmit: PropTypes.func.isRequired,
goToProfile: PropTypes.func.isRequired
};
componentWillMount() {
const step = this.props.match.params.step;
if (step && !/^[1-3]$/.test(step)) {
2017-07-22 21:27:38 +05:30
// wrong param value
this.props.history.push('/404');
}
}
render() {
const step = (parseInt(this.props.match.params.step, 10) || 1) - 1;
2017-07-22 21:27:38 +05:30
return (
<MultiFactorAuth
onSubmit={this.onSubmit}
step={step}
2017-07-22 21:27:38 +05:30
onChangeStep={this.onChangeStep}
onComplete={this.onComplete}
2017-07-22 21:27:38 +05:30
/>
);
}
onChangeStep = (step: MfaStep) => {
this.props.history.push(`/profile/mfa/step${step + 1}`);
2017-07-22 21:27:38 +05:30
};
onSubmit = (form: FormModel, sendData: () => Promise<*>) => {
2017-07-22 21:27:38 +05:30
return this.context.onSubmit({
form,
sendData
2017-07-22 21:27:38 +05:30
});
};
onComplete = () => {
this.context.goToProfile();
2017-07-22 21:27:38 +05:30
};
}
export default MultiFactorAuthPage;