2019-12-23 01:03:44 +00:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { useStoreState } from 'easy-peasy';
|
|
|
|
import { ApplicationStore } from '@/state';
|
2020-07-03 23:37:26 +01:00
|
|
|
import tw from 'twin.macro';
|
2022-07-02 23:53:03 +01:00
|
|
|
import { Button } from '@/components/elements/button/index';
|
|
|
|
import DisableTwoFactorModal from '@/components/dashboard/forms/DisableTwoFactorModal';
|
2022-07-03 18:43:54 +01:00
|
|
|
import SetupTOTPModal from '@/components/dashboard/forms/SetupTOTPModal';
|
|
|
|
import RecoveryTokensDialog from '@/components/dashboard/forms/RecoveryTokensDialog';
|
2019-12-23 01:03:44 +00:00
|
|
|
|
|
|
|
export default () => {
|
2022-07-03 18:43:54 +01:00
|
|
|
const [tokens, setTokens] = useState<string[]>([]);
|
2022-07-02 23:53:03 +01:00
|
|
|
const [visible, setVisible] = useState<'enable' | 'disable' | null>(null);
|
2021-05-16 20:35:49 +01:00
|
|
|
const isEnabled = useStoreState((state: ApplicationStore) => state.user.data!.useTotp);
|
2019-12-23 01:03:44 +00:00
|
|
|
|
2022-07-03 18:43:54 +01:00
|
|
|
const onTokens = (tokens: string[]) => {
|
|
|
|
setTokens(tokens);
|
|
|
|
setVisible(null);
|
|
|
|
};
|
|
|
|
|
2021-05-16 20:35:49 +01:00
|
|
|
return (
|
2019-12-23 01:03:44 +00:00
|
|
|
<div>
|
2022-07-03 18:43:54 +01:00
|
|
|
<SetupTOTPModal open={visible === 'enable'} onClose={() => setVisible(null)} onTokens={onTokens} />
|
|
|
|
<RecoveryTokensDialog tokens={tokens} open={tokens.length > 0} onClose={() => setTokens([])} />
|
2022-07-02 23:53:03 +01:00
|
|
|
<DisableTwoFactorModal visible={visible === 'disable'} onModalDismissed={() => setVisible(null)} />
|
2020-07-03 23:37:26 +01:00
|
|
|
<p css={tw`text-sm`}>
|
2022-06-26 20:13:52 +01:00
|
|
|
{isEnabled
|
2022-07-02 23:53:03 +01: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-23 01:03:44 +00:00
|
|
|
</p>
|
2020-07-03 23:37:26 +01:00
|
|
|
<div css={tw`mt-6`}>
|
2022-07-02 23:53:03 +01:00
|
|
|
{isEnabled ? (
|
|
|
|
<Button.Danger onClick={() => setVisible('disable')}>Disable Two-Step</Button.Danger>
|
|
|
|
) : (
|
|
|
|
<Button onClick={() => setVisible('enable')}>Enable Two-Step</Button>
|
|
|
|
)}
|
2019-12-23 01:03:44 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-05-16 20:35:49 +01:00
|
|
|
);
|
2019-12-23 01:03:44 +00:00
|
|
|
};
|