forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {useEffect, useState} from 'react'
2import {Trans} from '@lingui/macro'
3
4import {useAccountEmailState} from '#/components/dialogs/EmailDialog/data/useAccountEmailState'
5import {Disable} from '#/components/dialogs/EmailDialog/screens/Manage2FA/Disable'
6import {Enable} from '#/components/dialogs/EmailDialog/screens/Manage2FA/Enable'
7import {
8 ScreenID,
9 type ScreenProps,
10} from '#/components/dialogs/EmailDialog/types'
11
12export function Manage2FA({showScreen}: ScreenProps<ScreenID.Manage2FA>) {
13 const {isEmailVerified, email2FAEnabled} = useAccountEmailState()
14 const [requestedAction, setRequestedAction] = useState<
15 'enable' | 'disable' | null
16 >(null)
17
18 useEffect(() => {
19 if (!isEmailVerified) {
20 showScreen({
21 id: ScreenID.Verify,
22 instructions: [
23 <Trans key="2fa">
24 You need to verify your email address before you can enable email
25 2FA.
26 </Trans>,
27 ],
28 onVerify: () => {
29 showScreen({
30 id: ScreenID.Manage2FA,
31 })
32 },
33 })
34 }
35 }, [isEmailVerified, showScreen])
36
37 /*
38 * Wacky state handling so that once 2FA settings change, we don't show the
39 * wrong step of this form - esb
40 */
41
42 if (email2FAEnabled) {
43 if (!requestedAction) {
44 setRequestedAction('disable')
45 return <Disable />
46 }
47
48 if (requestedAction === 'disable') {
49 return <Disable />
50 }
51 if (requestedAction === 'enable') {
52 return <Enable />
53 }
54 } else {
55 if (!requestedAction) {
56 setRequestedAction('enable')
57 return <Enable />
58 }
59
60 if (requestedAction === 'disable') {
61 return <Disable />
62 }
63 if (requestedAction === 'enable') {
64 return <Enable />
65 }
66 }
67
68 // should never happen
69 return null
70}