2026-10-05 18:10:18 -04:00
|
|
|
import { useState } from 'react';
|
|
|
|
|
import Button from '@/components/elements/Button';
|
2022-07-03 14:27:37 -04:00
|
|
|
import SetupTOTPDialog from '@/components/dashboard/forms/SetupTOTPDialog';
|
2022-07-03 13:43:54 -04:00
|
|
|
import RecoveryTokensDialog from '@/components/dashboard/forms/RecoveryTokensDialog';
|
2022-07-03 14:27:37 -04:00
|
|
|
import DisableTOTPDialog from '@/components/dashboard/forms/DisableTOTPDialog';
|
2026-10-05 18:10:18 -04:00
|
|
|
import { useCurrentUser } from '@/api/account/queries';
|
2019-12-22 17:03:44 -08:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
function ConfigureTwoFactorForm() {
|
2022-07-03 13:43:54 -04:00
|
|
|
const [tokens, setTokens] = useState<string[]>([]);
|
2022-07-02 18:53:03 -04:00
|
|
|
const [visible, setVisible] = useState<'enable' | 'disable' | null>(null);
|
2026-10-05 18:10:18 -04:00
|
|
|
const isEnabled = useCurrentUser().useTotp;
|
2019-12-22 17:03:44 -08:00
|
|
|
|
2022-07-03 13:43:54 -04:00
|
|
|
const onTokens = (tokens: string[]) => {
|
|
|
|
|
setTokens(tokens);
|
|
|
|
|
setVisible(null);
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-16 12:35:49 -07:00
|
|
|
return (
|
2019-12-22 17:03:44 -08:00
|
|
|
<div>
|
2026-10-05 18:10:18 -04:00
|
|
|
<SetupTOTPDialog
|
|
|
|
|
open={visible === 'enable'}
|
|
|
|
|
enabled={visible === 'enable'}
|
|
|
|
|
onClose={() => setVisible(null)}
|
|
|
|
|
onTokens={onTokens}
|
|
|
|
|
/>
|
2022-07-03 13:43:54 -04:00
|
|
|
<RecoveryTokensDialog tokens={tokens} open={tokens.length > 0} onClose={() => setTokens([])} />
|
2022-07-03 14:27:37 -04:00
|
|
|
<DisableTOTPDialog open={visible === 'disable'} onClose={() => setVisible(null)} />
|
2026-10-05 18:10:18 -04:00
|
|
|
<p className={'text-sm'}>
|
2022-06-26 15:13:52 -04:00
|
|
|
{isEnabled
|
2022-07-02 18:53:03 -04:00
|
|
|
? 'Two-step verification is currently enabled on your account.'
|
|
|
|
|
: 'You do not currently have two-step verification enabled on your account. Click the button below to begin configuring it.'}
|
2019-12-22 17:03:44 -08:00
|
|
|
</p>
|
2026-10-05 18:10:18 -04:00
|
|
|
<div className={'mt-6'}>
|
2022-07-02 18:53:03 -04:00
|
|
|
{isEnabled ? (
|
|
|
|
|
<Button.Danger onClick={() => setVisible('disable')}>Disable Two-Step</Button.Danger>
|
|
|
|
|
) : (
|
|
|
|
|
<Button onClick={() => setVisible('enable')}>Enable Two-Step</Button>
|
|
|
|
|
)}
|
2019-12-22 17:03:44 -08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-05-16 12:35:49 -07:00
|
|
|
);
|
2026-10-05 18:10:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ConfigureTwoFactorForm;
|