|
| 1 | +import { useAuthControllerDelete } from '@baca/api/query/auth/auth' |
1 | 2 | import { ControlledField } from '@baca/components' |
2 | | -import { Button, Text, Spacer, Row, Box } from '@baca/design-system' |
| 3 | +import { Button, Text, Spacer, Row, Box, useBottomSheet } from '@baca/design-system' |
3 | 4 | import { useCallback, useTranslation, useUpdateProfileForm, useScreenOptions } from '@baca/hooks' |
| 5 | +import { signOut } from '@baca/store/auth' |
| 6 | +import { showErrorToast } from '@baca/utils' |
4 | 7 | import { useRouter } from 'expo-router' |
5 | 8 |
|
6 | 9 | export const ProfileScreen = () => { |
7 | 10 | const { t } = useTranslation() |
8 | 11 | const { back } = useRouter() |
| 12 | + const { mutateAsync: removeUserAccount, isLoading } = useAuthControllerDelete() |
| 13 | + const { control, errors, isSubmitting, setFocus, submit } = useUpdateProfileForm() |
| 14 | + |
| 15 | + const { bottomSheetComponentRenderFunction, closeBottomSheet, presentBottomSheet } = |
| 16 | + useBottomSheet({ |
| 17 | + title: '', |
| 18 | + isDivider: false, |
| 19 | + }) |
| 20 | + |
| 21 | + const handleRemoveUserAccount = useCallback(async () => { |
| 22 | + try { |
| 23 | + await removeUserAccount() |
| 24 | + signOut() |
| 25 | + } catch { |
| 26 | + showErrorToast({ |
| 27 | + description: t('errors.something_went_wrong'), |
| 28 | + }) |
| 29 | + } |
| 30 | + }, [removeUserAccount, t]) |
| 31 | + |
| 32 | + const bottomSheet = bottomSheetComponentRenderFunction( |
| 33 | + <Box px={4} pb={10}> |
| 34 | + <Text.LgSemibold color="text.primary" pt={4} pb={2}> |
| 35 | + {t('profile_screen.are_you_sure')} |
| 36 | + </Text.LgSemibold> |
| 37 | + <Text.SmRegular color="text.tertiary" lineHeight="md"> |
| 38 | + {t('profile_screen.remove_account_desc')} |
| 39 | + </Text.SmRegular> |
| 40 | + <Row w="full" justifyContent="space-between" pt={8}> |
| 41 | + <Button variant="SecondaryGray" flex={1} borderRadius={8} onPress={closeBottomSheet}> |
| 42 | + {t('common.cancel')} |
| 43 | + </Button> |
| 44 | + <Spacer x={3} /> |
| 45 | + <Button |
| 46 | + onPress={handleRemoveUserAccount} |
| 47 | + variant="PrimaryDestructive" |
| 48 | + flex={1} |
| 49 | + borderRadius={8} |
| 50 | + loading={isLoading} |
| 51 | + > |
| 52 | + {t('profile_screen.remove_account')} |
| 53 | + </Button> |
| 54 | + </Row> |
| 55 | + </Box>, |
| 56 | + { |
| 57 | + name: 'delete-bin-line', |
| 58 | + color: 'featured.icon.light.fg.error', |
| 59 | + bgColor: 'bg.error.secondary', |
| 60 | + } |
| 61 | + ) |
9 | 62 |
|
10 | 63 | useScreenOptions({ |
11 | 64 | title: t('navigation.screen_titles.profile'), |
12 | 65 | }) |
13 | 66 |
|
14 | | - const { control, errors, isSubmitting, setFocus, submit } = useUpdateProfileForm() |
15 | | - |
16 | 67 | const focusLastNameInput = useCallback(() => setFocus('lastName'), [setFocus]) |
17 | 68 |
|
18 | 69 | return ( |
19 | 70 | <Box m={8}> |
20 | | - {/* TODO: Add translations here */} |
21 | | - <Text.LgBold>Profile</Text.LgBold> |
22 | | - <Text.MdRegular>Update your personal details here.</Text.MdRegular> |
| 71 | + <Text.LgBold>{t('profile_screen.profile')}</Text.LgBold> |
| 72 | + <Text.MdRegular>{t('profile_screen.update_your_details')}</Text.MdRegular> |
23 | 73 | <Box borderColor="utility.gray.300" borderBottomWidth={2} borderTopWidth={2} my={4} py={4}> |
24 | 74 | <ControlledField.Input |
25 | 75 | {...{ control, errors }} |
@@ -73,6 +123,18 @@ export const ProfileScreen = () => { |
73 | 123 | {t('common.save')} |
74 | 124 | </Button> |
75 | 125 | </Row> |
| 126 | + <Box borderColor="utility.gray.300" borderTopWidth={2} my={4} py={6}> |
| 127 | + <Button |
| 128 | + leftIconName="delete-bin-line" |
| 129 | + variant="SecondaryDestructive" |
| 130 | + w="1/2" |
| 131 | + borderRadius={8} |
| 132 | + onPress={presentBottomSheet} |
| 133 | + > |
| 134 | + {t('profile_screen.remove_account')} |
| 135 | + </Button> |
| 136 | + {bottomSheet} |
| 137 | + </Box> |
76 | 138 | </Box> |
77 | 139 | ) |
78 | 140 | } |
0 commit comments