2017-09-09 19:52:19 +05:30
|
|
|
// @flow
|
|
|
|
import React, { Component } from 'react';
|
2019-01-28 00:42:58 +05:30
|
|
|
import PropTypes from 'prop-types';
|
2017-09-09 19:52:19 +05:30
|
|
|
|
|
|
|
import logger from 'services/logger';
|
2019-01-28 00:42:58 +05:30
|
|
|
import { disable as disableMFA } from 'services/api/mfa';
|
2017-09-09 19:52:19 +05:30
|
|
|
|
|
|
|
import MfaDisableForm from './disableForm/MfaDisableForm';
|
|
|
|
import MfaStatus from './status/MfaStatus';
|
|
|
|
|
|
|
|
import type { FormModel } from 'components/ui/form';
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
export default class MfaDisable extends Component<
|
|
|
|
{
|
2017-09-09 19:52:19 +05:30
|
|
|
onSubmit: (form: FormModel, sendData: () => Promise<*>) => Promise<*>,
|
2019-11-27 14:33:32 +05:30
|
|
|
onComplete: Function,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
showForm?: boolean,
|
|
|
|
},
|
|
|
|
> {
|
|
|
|
static contextTypes = {
|
|
|
|
userId: PropTypes.number.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {};
|
|
|
|
|
|
|
|
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 data = form.serialize();
|
|
|
|
|
|
|
|
return disableMFA(this.context.userId, data);
|
|
|
|
})
|
|
|
|
.then(() => this.props.onComplete())
|
|
|
|
.catch(resp => {
|
|
|
|
const { errors } = resp || {};
|
|
|
|
|
|
|
|
if (errors) {
|
|
|
|
return Promise.reject(errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.error('MFA: Unexpected disable form result', {
|
|
|
|
resp,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2017-09-09 19:52:19 +05:30
|
|
|
}
|