Skip to content

Commit 783e36d

Browse files
committed
chore: ProfileDeleteAccountButton added among others
1 parent fe6900e commit 783e36d

3 files changed

Lines changed: 82 additions & 65 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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, useScreenOptions } 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+
useScreenOptions({
60+
title: t('navigation.screen_titles.profile'),
61+
})
62+
63+
return (
64+
<Box>
65+
<Box borderColor="border.secondary" borderTopWidth={1} my={4} py={6} alignItems="flex-start">
66+
<Button
67+
leftIconName="delete-bin-line"
68+
variant="SecondaryDestructive"
69+
borderRadius={8}
70+
onPress={presentBottomSheet}
71+
>
72+
{t('profile_screen.remove_account')}
73+
</Button>
74+
{bottomSheet}
75+
</Box>
76+
</Box>
77+
)
78+
}

src/components/screens/profile/ProfilePasswordForm.tsx

Whitespace-only changes.

src/screens/ProfileScreen.tsx

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,15 @@
1-
import { useAuthControllerDelete } from '@baca/api/query/auth/auth'
1+
import { ProfileDeleteAccountButton } from '@baca/components/screens/profile/ProfileDeleteAccountButton'
22
import { ProfileDetailsForm } from '@baca/components/screens/profile/ProfileDetailsForm'
33
import { ProfileHeader } from '@baca/components/screens/profile/ProfileHeader'
4-
import { Button, Text, Spacer, Row, Box, useBottomSheet } from '@baca/design-system'
5-
import { useCallback, useTranslation, useUpdateProfileForm, useScreenOptions } from '@baca/hooks'
6-
import { signOut } from '@baca/store/auth'
7-
import { showErrorToast } from '@baca/utils'
4+
import { Button, Spacer, Row, Box } from '@baca/design-system'
5+
import { useTranslation, useUpdateProfileForm, useScreenOptions } from '@baca/hooks'
86
import { useRouter } from 'expo-router'
97

108
export const ProfileScreen = () => {
119
const { t } = useTranslation()
1210
const { back } = useRouter()
13-
const { mutateAsync: removeUserAccount, isLoading } = useAuthControllerDelete()
1411
const { isSubmitting, submit } = useUpdateProfileForm()
1512

16-
const { bottomSheetComponentRenderFunction, closeBottomSheet, presentBottomSheet } =
17-
useBottomSheet({
18-
title: '',
19-
isDivider: false,
20-
})
21-
22-
const handleRemoveUserAccount = useCallback(async () => {
23-
try {
24-
await removeUserAccount()
25-
signOut()
26-
} catch {
27-
showErrorToast({
28-
description: t('errors.something_went_wrong'),
29-
})
30-
}
31-
}, [removeUserAccount, t])
32-
33-
const bottomSheet = bottomSheetComponentRenderFunction(
34-
<Box px={4} pb={10}>
35-
<Text.LgSemibold color="text.primary" pt={4} pb={2}>
36-
{t('profile_screen.are_you_sure')}
37-
</Text.LgSemibold>
38-
<Text.SmRegular color="text.secondary" lineHeight="md">
39-
{t('profile_screen.remove_account_desc')}
40-
</Text.SmRegular>
41-
<Row w="full" justifyContent="space-between" pt={8}>
42-
<Button variant="SecondaryGray" flex={1} borderRadius={8} onPress={closeBottomSheet}>
43-
{t('common.cancel')}
44-
</Button>
45-
<Spacer x={3} />
46-
<Button
47-
onPress={handleRemoveUserAccount}
48-
variant="PrimaryDestructive"
49-
flex={1}
50-
borderRadius={8}
51-
loading={isLoading}
52-
>
53-
{t('profile_screen.remove_account')}
54-
</Button>
55-
</Row>
56-
</Box>,
57-
{
58-
name: 'delete-bin-line',
59-
color: 'featured.icon.light.fg.error',
60-
bgColor: 'bg.error.secondary',
61-
}
62-
)
63-
6413
useScreenOptions({
6514
title: t('navigation.screen_titles.profile'),
6615
})
@@ -89,17 +38,7 @@ export const ProfileScreen = () => {
8938
{t('common.save')}
9039
</Button>
9140
</Row>
92-
<Box borderColor="border.secondary" borderTopWidth={1} my={4} py={6} alignItems="flex-start">
93-
<Button
94-
leftIconName="delete-bin-line"
95-
variant="SecondaryDestructive"
96-
borderRadius={8}
97-
onPress={presentBottomSheet}
98-
>
99-
{t('profile_screen.remove_account')}
100-
</Button>
101-
{bottomSheet}
102-
</Box>
41+
<ProfileDeleteAccountButton />
10342
</Box>
10443
)
10544
}

0 commit comments

Comments
 (0)