import React from 'react' import { ActivityIndicator, StyleSheet, TouchableOpacity, View, } from 'react-native' import {TextInput} from './util' import LinearGradient from 'react-native-linear-gradient' import * as Toast from '../util/Toast' import {Text} from '../util/text/Text' import {useStores} from 'state/index' import {s, colors, gradients} from 'lib/styles' import {usePalette} from 'lib/hooks/usePalette' import {useTheme} from 'lib/ThemeContext' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' import {ErrorMessage} from '../util/error/ErrorMessage' import {cleanError} from 'lib/strings/errors' import {resetToTab} from '../../../Navigation' export const snapPoints = ['60%'] export function Component({}: {}) { const pal = usePalette('default') const theme = useTheme() const store = useStores() const {isMobile} = useWebMediaQueries() const [isEmailSent, setIsEmailSent] = React.useState(false) const [confirmCode, setConfirmCode] = React.useState('') const [password, setPassword] = React.useState('') const [isProcessing, setIsProcessing] = React.useState(false) const [error, setError] = React.useState('') const onPressSendEmail = async () => { setError('') setIsProcessing(true) try { await store.agent.com.atproto.server.requestAccountDelete() setIsEmailSent(true) } catch (e: any) { setError(cleanError(e)) } setIsProcessing(false) } const onPressConfirmDelete = async () => { setError('') setIsProcessing(true) const token = confirmCode.replace(/\s/g, '') try { await store.agent.com.atproto.server.deleteAccount({ did: store.me.did, password, token, }) Toast.show('Your account has been deleted') resetToTab('HomeTab') store.session.clear() store.shell.closeModal() } catch (e: any) { setError(cleanError(e)) } setIsProcessing(false) } const onCancel = () => { store.shell.closeModal() } return ( Delete Account {' "'} {store.me.handle} {'"'} {!isEmailSent ? ( <> For security reasons, we'll need to send a confirmation code to your email address. {error ? ( ) : undefined} {isProcessing ? ( ) : ( <> Send Email Cancel )} ) : ( <> {/* TODO: Update this label to be more concise */} Check your inbox for an email with the confirmation code to enter below: Please enter your password as well: {error ? ( ) : undefined} {isProcessing ? ( ) : ( <> Delete my account Cancel )} )} ) } const styles = StyleSheet.create({ container: { flex: 1, }, innerContainer: { paddingBottom: 20, }, titleContainer: { display: 'flex', flexDirection: 'row', justifyContent: 'center', flexWrap: 'wrap', marginTop: 12, marginBottom: 12, marginLeft: 20, marginRight: 20, }, titleMobile: { textAlign: 'center', }, titleDesktop: { textAlign: 'center', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis', // @ts-ignore only rendered on web maxWidth: '400px', }, description: { textAlign: 'center', paddingHorizontal: 22, marginBottom: 10, }, mt20: { marginTop: 20, }, mb20: { marginBottom: 20, }, textInput: { borderWidth: 1, borderRadius: 6, paddingHorizontal: 16, paddingVertical: 12, fontSize: 20, marginHorizontal: 20, }, btn: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', borderRadius: 32, padding: 14, marginHorizontal: 20, }, evilBtn: { backgroundColor: colors.red4, }, })