Bluesky app fork with some witchin' additions 馃挮
at main 129 lines 3.9 kB view raw
1import React from 'react' 2import {View} from 'react-native' 3import {msg} from '@lingui/core/macro' 4import {useLingui} from '@lingui/react' 5import {Trans} from '@lingui/react/macro' 6 7import {logger} from '#/logger' 8import {useAgent, useSessionApi} from '#/state/session' 9import {atoms as a, useTheme} from '#/alf' 10import {Button, ButtonIcon, ButtonText} from '#/components/Button' 11import {type DialogOuterProps} from '#/components/Dialog' 12import {Divider} from '#/components/Divider' 13import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo' 14import {Loader} from '#/components/Loader' 15import * as Prompt from '#/components/Prompt' 16import {Text} from '#/components/Typography' 17 18export function DeactivateAccountDialog({ 19 control, 20}: { 21 control: DialogOuterProps['control'] 22}) { 23 return ( 24 <Prompt.Outer control={control}> 25 <DeactivateAccountDialogInner control={control} /> 26 </Prompt.Outer> 27 ) 28} 29 30function DeactivateAccountDialogInner({ 31 control, 32}: { 33 control: DialogOuterProps['control'] 34}) { 35 const t = useTheme() 36 const {_} = useLingui() 37 const agent = useAgent() 38 const {logoutCurrentAccount} = useSessionApi() 39 const [pending, setPending] = React.useState(false) 40 const [error, setError] = React.useState<string | undefined>() 41 42 const handleDeactivate = React.useCallback(async () => { 43 try { 44 setPending(true) 45 await agent.com.atproto.server.deactivateAccount({}) 46 control.close(() => { 47 logoutCurrentAccount('Deactivated') 48 }) 49 } catch (e: any) { 50 switch (e.message) { 51 case 'Bad token scope': 52 setError( 53 _( 54 msg`You're signed in with an App Password. Please sign in with your main password to continue deactivating your account.`, 55 ), 56 ) 57 break 58 default: 59 setError(_(msg`Something went wrong, please try again`)) 60 break 61 } 62 63 logger.error(e, { 64 message: 'Failed to deactivate account', 65 }) 66 } finally { 67 setPending(false) 68 } 69 }, [agent, control, logoutCurrentAccount, _, setPending]) 70 71 return ( 72 <> 73 <Prompt.TitleText>{_(msg`Deactivate account`)}</Prompt.TitleText> 74 <Prompt.DescriptionText> 75 <Trans> 76 Your profile, posts, feeds, and lists will no longer be visible to 77 other Bluesky users. You can reactivate your account at any time by 78 logging in. 79 </Trans> 80 </Prompt.DescriptionText> 81 82 <View style={[a.pb_xl]}> 83 <Divider /> 84 <View style={[a.gap_sm, a.pt_lg, a.pb_xl]}> 85 <Text style={[t.atoms.text_contrast_medium, a.leading_snug]}> 86 <Trans> 87 There is no time limit for account deactivation, come back any 88 time. 89 </Trans> 90 </Text> 91 <Text style={[t.atoms.text_contrast_medium, a.leading_snug]}> 92 <Trans> 93 If you're trying to change your handle or email, do so before you 94 deactivate. 95 </Trans> 96 </Text> 97 </View> 98 99 <Divider /> 100 </View> 101 <Prompt.Actions> 102 <Button 103 color="negative" 104 size="large" 105 label={_(msg`Yes, deactivate`)} 106 onPress={handleDeactivate}> 107 <ButtonText>{_(msg`Yes, deactivate`)}</ButtonText> 108 {pending && <ButtonIcon icon={Loader} position="right" />} 109 </Button> 110 <Prompt.Cancel /> 111 </Prompt.Actions> 112 113 {error && ( 114 <View 115 style={[ 116 a.flex_row, 117 a.gap_sm, 118 a.mt_md, 119 a.p_md, 120 a.rounded_sm, 121 t.atoms.bg_contrast_25, 122 ]}> 123 <CircleInfo size="md" fill={t.palette.negative_400} /> 124 <Text style={[a.flex_1, a.leading_snug]}>{error}</Text> 125 </View> 126 )} 127 </> 128 ) 129}