import React from 'react'; import { Form, Formik, FormikActions } from 'formik'; import Modal, { RequiredModalProps } from '@/components/elements/Modal'; import FlashMessageRender from '@/components/FlashMessageRender'; import Field from '@/components/elements/Field'; import { object, string } from 'yup'; import { Actions, useStoreActions } from 'easy-peasy'; import { ApplicationStore } from '@/state'; import disableAccountTwoFactor from '@/api/account/disableAccountTwoFactor'; import { httpErrorToHuman } from '@/api/http'; interface Values { password: string; } export default ({ ...props }: RequiredModalProps) => { const { addError, clearFlashes } = useStoreActions((actions: Actions) => actions.flashes); const updateUserData = useStoreActions((actions: Actions) => actions.user.updateUserData); const submit = ({ password }: Values, { setSubmitting }: FormikActions) => { clearFlashes('account:two-factor'); disableAccountTwoFactor(password) .then(() => { updateUserData({ useTotp: false }); props.onDismissed(); }) .catch(error => { console.error(error); addError({ message: httpErrorToHuman(error), key: 'account:two-factor' }); setSubmitting(false); }); }; return ( {({ isSubmitting, isValid }) => (
)}
); };