Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189import {useCallback, useState} from 'react'import {View} from 'react-native'import {msg} from '@lingui/core/macro'import {useLingui} from '@lingui/react'import {Trans} from '@lingui/react/macro'
import {gateDeactivateAccount} from '#/lib/api/gatekeeper'import {useBrand} from '#/lib/community/BrandContext'import {useIsBlackskyPds} from '#/lib/hooks/useIsBlackskyPds'import {logger} from '#/logger'import {useAgent, useSession, useSessionApi} from '#/state/session'import {atoms as a, useTheme} from '#/alf'import {Button, ButtonIcon, ButtonText} from '#/components/Button'import {type DialogOuterProps} from '#/components/Dialog'import {Divider} from '#/components/Divider'import * as TextField from '#/components/forms/TextField'import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'import {Lock_Stroke2_Corner2_Rounded as Lock} from '#/components/icons/Lock'import {Loader} from '#/components/Loader'import * as Prompt from '#/components/Prompt'import {Text} from '#/components/Typography'
export function DeactivateAccountDialog({ control,}: { control: DialogOuterProps['control']}) { return ( <Prompt.Outer control={control}> <DeactivateAccountDialogInner control={control} /> </Prompt.Outer> )}
function DeactivateAccountDialogInner({ control,}: { control: DialogOuterProps['control']}) { const t = useTheme() const {_} = useLingui() const brand = useBrand() const agent = useAgent() const {currentAccount} = useSession() const {logoutCurrentAccount} = useSessionApi() const [pending, setPending] = useState(false) const [error, setError] = useState<string | undefined>() const [password, setPassword] = useState('')
const isOauth = currentAccount?.isOauthSession === true const isBskyPds = useIsBlackskyPds() const useGatekeeper = isOauth && isBskyPds
const handleDeactivate = useCallback(async () => { try { setPending(true) if (useGatekeeper) { if (!password) { setError(_(msg`Please enter your password.`)) setPending(false) return } await gateDeactivateAccount({ serviceUrl: currentAccount.service, did: currentAccount.did, password, }) } else { await agent.com.atproto.server.deactivateAccount({}) } control.close(() => { logoutCurrentAccount('Deactivated') }) } catch (e: any) { switch (e.message) { case 'Bad token scope': setError( _( msg`You're signed in with an App Password. Please sign in with your main password to continue deactivating your account.`, ), ) break case 'Invalid password': setError(_(msg`Invalid password. Please try again.`)) break default: setError(_(msg`Something went wrong, please try again`)) break }
logger.error(e, { message: 'Failed to deactivate account', }) } finally { setPending(false) } }, [ agent, control, logoutCurrentAccount, _, setPending, useGatekeeper, password, currentAccount, ])
return ( <> <Prompt.TitleText>{_(msg`Deactivate account`)}</Prompt.TitleText> <Prompt.DescriptionText> <Trans> Your profile, posts, feeds, and lists will no longer be visible to other {brand.metadata.displayName} users. You can reactivate your account at any time by logging in. </Trans> </Prompt.DescriptionText>
<View style={[a.pb_xl]}> <Divider /> <View style={[a.gap_sm, a.pt_lg, a.pb_xl]}> <Text style={[t.atoms.text_contrast_medium, a.leading_snug]}> <Trans> There is no time limit for account deactivation, come back any time. </Trans> </Text> <Text style={[t.atoms.text_contrast_medium, a.leading_snug]}> <Trans> If you're trying to change your handle or email, do so before you deactivate. </Trans> </Text> </View>
{useGatekeeper && ( <View style={[a.pb_lg]}> <Text style={[a.pb_sm, a.leading_snug, t.atoms.text_contrast_medium]}> <Trans>Please enter your password to continue.</Trans> </Text> <TextField.Root> <TextField.Icon icon={Lock} /> <TextField.Input label={_(msg`Password`)} placeholder={_(msg`Password`)} defaultValue={password} onChangeText={setPassword} secureTextEntry autoComplete="password" autoCapitalize="none" /> </TextField.Root> </View> )}
<Divider /> </View> <Prompt.Actions> <Button color="negative" size="large" label={_(msg`Yes, deactivate`)} onPress={handleDeactivate} disabled={useGatekeeper && !password}> <ButtonText>{_(msg`Yes, deactivate`)}</ButtonText> {pending && <ButtonIcon icon={Loader} position="right" />} </Button> <Prompt.Cancel /> </Prompt.Actions>
{error && ( <View style={[ a.flex_row, a.gap_sm, a.mt_md, a.p_md, a.rounded_sm, t.atoms.bg_contrast_25, ]}> <CircleInfo size="md" fill={t.palette.negative_400} /> <Text style={[a.flex_1, a.leading_snug]}>{error}</Text> </View> )} </> )}