import {useCallback, useState} from 'react' import {useLingui} from '@lingui/react/macro' import {useSession} from '#/state/session' import {web} from '#/alf' import * as Dialog from '#/components/Dialog' import {type StatefulControl} from '#/components/dialogs/Context' import {useGlobalDialogsControlContext} from '#/components/dialogs/Context' import {useAccountEmailState} from '#/components/dialogs/EmailDialog/data/useAccountEmailState' import {Manage2FA} from '#/components/dialogs/EmailDialog/screens/Manage2FA' import {Update} from '#/components/dialogs/EmailDialog/screens/Update' import {VerificationReminder} from '#/components/dialogs/EmailDialog/screens/VerificationReminder' import {Verify} from '#/components/dialogs/EmailDialog/screens/Verify' import {type Screen, ScreenID} from '#/components/dialogs/EmailDialog/types' import {LegacyAuthRequiredDialogContent} from '#/components/dialogs/LegacyAuthRequiredDialog' import {OAuthPermissionGate} from '#/components/dialogs/OAuthPermissionGate' export type {Screen} from '#/components/dialogs/EmailDialog/types' export {ScreenID as EmailDialogScreenID} from '#/components/dialogs/EmailDialog/types' export function useEmailDialogControl() { return useGlobalDialogsControlContext().emailDialogControl } export function EmailDialog() { const {t: l} = useLingui() const emailDialogControl = useEmailDialogControl() const {isEmailVerified} = useAccountEmailState() const onClose = useCallback(() => { if (!isEmailVerified) { if (emailDialogControl.value?.id === ScreenID.Verify) { emailDialogControl.value.onCloseWithoutVerifying?.() } } emailDialogControl.clear() }, [isEmailVerified, emailDialogControl]) return ( ) } function Inner({control}: {control: StatefulControl}) { const {currentAccount} = useSession() const [screen, showScreen] = useState(() => control.value) if (!screen) return null // The PDS disallows OAuth for email updates and login 2FA settings. if ( currentAccount?.isOauthSession && (screen.id === ScreenID.Update || screen.id === ScreenID.Manage2FA) ) { return } switch (screen.id) { case ScreenID.Update: { return } case ScreenID.Verify: { return ( ) } case ScreenID.VerificationReminder: { return } case ScreenID.Manage2FA: { return } default: { return null } } }