import React, { useContext } from 'react'; import { Form, Formik, FormikHelpers } from 'formik'; 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 tw from 'twin.macro'; import Button from '@/components/elements/Button'; import asModal from '@/hoc/asModal'; import ModalContext from '@/context/ModalContext'; interface Values { password: string; } const DisableTwoFactorModal = () => { const { dismiss, setPropOverrides } = useContext(ModalContext); const { clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); const updateUserData = useStoreActions((actions: Actions) => actions.user.updateUserData); const submit = ({ password }: Values, { setSubmitting }: FormikHelpers) => { setPropOverrides({ showSpinnerOverlay: true, dismissable: false }); disableAccountTwoFactor(password) .then(() => { updateUserData({ useTotp: false }); dismiss(); }) .catch((error) => { console.error(error); clearAndAddHttpError({ error, key: 'account:two-factor' }); setSubmitting(false); setPropOverrides(null); }); }; return ( {({ isValid }) => (
)}
); }; export default asModal()(DisableTwoFactorModal);