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