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