import { useContext, useEffect, useState } from 'react'; import * as React from 'react'; import asDialog from '@/hoc/asDialog'; import { Dialog, DialogWrapperContext } from '@/components/elements/dialog'; import { Button } from '@/components/elements/button/index'; import { Input } from '@/components/elements/inputs'; import Tooltip from '@/components/elements/tooltip/Tooltip'; import disableAccountTwoFactor from '@/api/account/disableAccountTwoFactor'; import { useFlashKey } from '@/plugins/useFlash'; import { useStoreActions } from '@/state/hooks'; import FlashMessageRender from '@/components/FlashMessageRender'; const DisableTOTPDialog = () => { const [submitting, setSubmitting] = useState(false); const [password, setPassword] = useState(''); const { clearAndAddHttpError } = useFlashKey('account:two-step'); const { close, setProps } = useContext(DialogWrapperContext); const updateUserData = useStoreActions(actions => actions.user.updateUserData); useEffect(() => { setProps(state => ({ ...state, preventExternalClose: submitting })); }, [submitting]); const submit = (e: React.FormEvent) => { e.preventDefault(); e.stopPropagation(); if (submitting) return; setSubmitting(true); clearAndAddHttpError(); disableAccountTwoFactor(password) .then(() => { updateUserData({ useTotp: false }); close(); }) .catch(clearAndAddHttpError) .then(() => setSubmitting(false)); }; return (
setPassword(e.currentTarget.value)} /> Cancel 0} content={'You must enter your account password to continue.'} > Disable ); }; export default asDialog({ title: 'Disable Two-Step Verification', description: 'Disabling two-step verification will make your account less secure.', })(DisableTOTPDialog);