mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-11 15:59:06 +05:30
60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import logger from 'app/services/logger';
|
|
import { disable as disableMFA } from 'app/services/api/mfa';
|
|
import { FormModel } from 'app/components/ui/form';
|
|
|
|
import MfaDisableForm from './disableForm/MfaDisableForm';
|
|
import MfaStatus from './status/MfaStatus';
|
|
|
|
export default class MfaDisable extends React.Component<
|
|
{
|
|
onSubmit: (form: FormModel, sendData: () => Promise<void>) => Promise<void>;
|
|
onComplete: () => void;
|
|
},
|
|
{
|
|
showForm: boolean;
|
|
}
|
|
> {
|
|
static contextTypes = {
|
|
userId: PropTypes.number.isRequired,
|
|
};
|
|
|
|
state = {
|
|
showForm: false,
|
|
};
|
|
|
|
render() {
|
|
const { showForm } = this.state;
|
|
|
|
return showForm ? (
|
|
<MfaDisableForm onSubmit={this.onSubmit} />
|
|
) : (
|
|
<MfaStatus onProceed={this.onProceed} />
|
|
);
|
|
}
|
|
|
|
onProceed = () => this.setState({ showForm: true });
|
|
|
|
onSubmit = (form: FormModel) => {
|
|
return this.props
|
|
.onSubmit(form, () => {
|
|
const { totp } = form.serialize() as { totp: string };
|
|
|
|
return disableMFA(this.context.userId, totp);
|
|
})
|
|
.then(() => this.props.onComplete())
|
|
.catch(resp => {
|
|
const { errors } = resp || {};
|
|
|
|
if (errors) {
|
|
return Promise.reject(errors);
|
|
}
|
|
|
|
logger.error('MFA: Unexpected disable form result', {
|
|
resp,
|
|
});
|
|
});
|
|
};
|
|
}
|