|
| 1 | +import { useAuthControllerDelete } from '@baca/api/query/auth/auth' |
| 2 | +import { Button, Text, Spacer, Row, Box, useBottomSheet } from '@baca/design-system' |
| 3 | +import { useCallback, useTranslation } from '@baca/hooks' |
| 4 | +import { signOut } from '@baca/store/auth' |
| 5 | +import { showErrorToast } from '@baca/utils' |
| 6 | + |
| 7 | +export const ProfileDeleteAccountButton = () => { |
| 8 | + const { t } = useTranslation() |
| 9 | + const { mutateAsync: removeUserAccount, isLoading } = useAuthControllerDelete() |
| 10 | + |
| 11 | + const { bottomSheetComponentRenderFunction, closeBottomSheet, presentBottomSheet } = |
| 12 | + useBottomSheet({ |
| 13 | + title: '', |
| 14 | + isDivider: false, |
| 15 | + }) |
| 16 | + |
| 17 | + const handleRemoveUserAccount = useCallback(async () => { |
| 18 | + try { |
| 19 | + await removeUserAccount() |
| 20 | + signOut() |
| 21 | + } catch { |
| 22 | + showErrorToast({ |
| 23 | + description: t('errors.something_went_wrong'), |
| 24 | + }) |
| 25 | + } |
| 26 | + }, [removeUserAccount, t]) |
| 27 | + |
| 28 | + const bottomSheet = bottomSheetComponentRenderFunction( |
| 29 | + <Box px={4} pb={10}> |
| 30 | + <Text.LgSemibold color="text.primary" pt={4} pb={2}> |
| 31 | + {t('profile_screen.are_you_sure')} |
| 32 | + </Text.LgSemibold> |
| 33 | + <Text.SmRegular color="text.secondary" lineHeight="md"> |
| 34 | + {t('profile_screen.remove_account_desc')} |
| 35 | + </Text.SmRegular> |
| 36 | + <Row w="full" justifyContent="space-between" pt={8}> |
| 37 | + <Button variant="SecondaryGray" flex={1} borderRadius={8} onPress={closeBottomSheet}> |
| 38 | + {t('common.cancel')} |
| 39 | + </Button> |
| 40 | + <Spacer x={3} /> |
| 41 | + <Button |
| 42 | + onPress={handleRemoveUserAccount} |
| 43 | + variant="PrimaryDestructive" |
| 44 | + flex={1} |
| 45 | + borderRadius={8} |
| 46 | + loading={isLoading} |
| 47 | + > |
| 48 | + {t('profile_screen.remove_account')} |
| 49 | + </Button> |
| 50 | + </Row> |
| 51 | + </Box>, |
| 52 | + { |
| 53 | + name: 'delete-bin-line', |
| 54 | + color: 'featured.icon.light.fg.error', |
| 55 | + bgColor: 'bg.error.secondary', |
| 56 | + } |
| 57 | + ) |
| 58 | + |
| 59 | + return ( |
| 60 | + <Box borderColor="border.secondary" borderTopWidth={1} py={6} alignItems="flex-start"> |
| 61 | + <Button |
| 62 | + leftIconName="delete-bin-line" |
| 63 | + variant="SecondaryDestructive" |
| 64 | + borderRadius={8} |
| 65 | + onPress={presentBottomSheet} |
| 66 | + > |
| 67 | + {t('profile_screen.remove_account')} |
| 68 | + </Button> |
| 69 | + {bottomSheet} |
| 70 | + </Box> |
| 71 | + ) |
| 72 | +} |
0 commit comments