import {useCallback, useState} from 'react' import {View} from 'react-native' import {useSafeAreaInsets} from 'react-native-safe-area-context' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' import {Trans} from '@lingui/react/macro' import {useQueryClient} from '@tanstack/react-query' import {useAccountSwitcher} from '#/lib/hooks/useAccountSwitcher' import {isErrorMaybeAppPasswordPermissions} from '#/lib/strings/errors' import {logger} from '#/logger' import { type SessionAccount, usePdsClient, useSession, useSessionApi, } from '#/state/session' import {useLoggedOutViewControls} from '#/state/shell/logged-out' import {Logo} from '#/view/icons/Logo' import {atoms as a, useTheme} from '#/alf' import {AccountList} from '#/components/AccountList' import {Button, ButtonIcon, ButtonText} from '#/components/Button' import {Divider} from '#/components/Divider' import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo' import * as Layout from '#/components/Layout' import {Loader} from '#/components/Loader' import {Text} from '#/components/Typography' import {IS_WEB} from '#/env' import {com} from '#/lexicons' const COL_WIDTH = 400 export function Deactivated() { const {_} = useLingui() const t = useTheme() const insets = useSafeAreaInsets() const {currentAccount, accounts} = useSession() const {onPressSwitchAccount, pendingDid} = useAccountSwitcher() const {setShowLoggedOut} = useLoggedOutViewControls() const hasOtherAccounts = accounts.length > 1 const {logoutCurrentAccount, refreshSession} = useSessionApi() const pdsClient = usePdsClient() const [pending, setPending] = useState(false) const [error, setError] = useState() const queryClient = useQueryClient() const onSelectAccount = useCallback( (account: SessionAccount) => { if (account.did !== currentAccount?.did) { onPressSwitchAccount(account, 'SwitchAccount') } }, [currentAccount, onPressSwitchAccount], ) const onPressAddAccount = useCallback(() => { setShowLoggedOut(true) }, [setShowLoggedOut]) const onPressLogout = useCallback(() => { if (IS_WEB) { // We're switching accounts, which remounts the entire app. // On mobile, this gets us Home, but on the web we also need reset the URL. // We can't change the URL via a navigate() call because the navigator // itself is about to unmount, and it calls pushState() too late. // So we change the URL ourselves. The navigator will pick it up on remount. history.pushState(null, '', '/') } logoutCurrentAccount('Deactivated') }, [logoutCurrentAccount]) const handleActivate = useCallback(async () => { try { setPending(true) await pdsClient.call(com.atproto.server.activateAccount) await queryClient.resetQueries() await refreshSession() } catch (e: any) { /* * `activateAccount` declares no lexicon errors, so the app-password case * arrives as an undeclared code plus a message. The shared helper matches * both that and the plain-string form the old exact `e.message` switch * relied on. */ if (isErrorMaybeAppPasswordPermissions(e)) { setError( _( msg`You're signed in with an App Password. Please sign in with your main password to continue deactivating your account.`, ), ) } else { setError(_(msg`Something went wrong, please try again`)) } logger.error(e, { message: 'Failed to activate account', }) } finally { setPending(false) } }, [_, pdsClient, refreshSession, setPending, setError, queryClient]) return ( Welcome back! You previously deactivated @{currentAccount?.handle}. You can reactivate your account to continue logging in. Your profile and posts will be visible to other users. {error && ( {error} )} {hasOtherAccounts ? ( <> Or, sign in to one of your other accounts. ) : ( <> Or, continue with another account. )} ) }