Path: blob/develop/resources/scripts/components/dashboard/forms/ConfigureTwoFactorForm.tsx
7454 views
import { useEffect, useState } from 'react';1import { useStoreState } from 'easy-peasy';2import { ApplicationStore } from '@/state';3import tw from 'twin.macro';4import { Button } from '@/components/elements/button/index';5import SetupTOTPDialog from '@/components/dashboard/forms/SetupTOTPDialog';6import RecoveryTokensDialog from '@/components/dashboard/forms/RecoveryTokensDialog';7import DisableTOTPDialog from '@/components/dashboard/forms/DisableTOTPDialog';8import { useFlashKey } from '@/plugins/useFlash';910export default () => {11const [tokens, setTokens] = useState<string[]>([]);12const [visible, setVisible] = useState<'enable' | 'disable' | null>(null);13const isEnabled = useStoreState((state: ApplicationStore) => state.user.data!.useTotp);14const { clearAndAddHttpError } = useFlashKey('account:two-step');1516useEffect(() => {17return () => {18clearAndAddHttpError();19};20}, [visible]);2122const onTokens = (tokens: string[]) => {23setTokens(tokens);24setVisible(null);25};2627return (28<div>29<SetupTOTPDialog open={visible === 'enable'} onClose={() => setVisible(null)} onTokens={onTokens} />30<RecoveryTokensDialog tokens={tokens} open={tokens.length > 0} onClose={() => setTokens([])} />31<DisableTOTPDialog open={visible === 'disable'} onClose={() => setVisible(null)} />32<p css={tw`text-sm`}>33{isEnabled34? 'Two-step verification is currently enabled on your account.'35: 'You do not currently have two-step verification enabled on your account. Click the button below to begin configuring it.'}36</p>37<div css={tw`mt-6`}>38{isEnabled ? (39<Button.Danger onClick={() => setVisible('disable')}>Disable Two-Step</Button.Danger>40) : (41<Button onClick={() => setVisible('enable')}>Enable Two-Step</Button>42)}43</div>44</div>45);46};474849