Skip to content

Commit 381e133

Browse files
committed
move remove account button to profile; remove unused translations
1 parent ee3916d commit 381e133

4 files changed

Lines changed: 71 additions & 48 deletions

File tree

src/i18n/translations/en.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
"session_expired": {
1010
"description": "Try to log in again",
1111
"title": "Your current session expired"
12-
},
13-
"remove_account": {
14-
"description": "Are you sure you want to delete your account?",
15-
"title": "Attention!",
16-
"confirm": "Yes, delete"
1712
}
1813
},
1914
"bottom_tabs": {
@@ -34,8 +29,7 @@
3429
"save": "Save",
3530
"search": "Search",
3631
"try_again_later": "Please try again later",
37-
"try_again": "Try again",
38-
"remove_account": "Remove account"
32+
"try_again": "Try again"
3933
},
4034
"errors": {
4135
"invalid_email": "Niepoprawny adres e-mail",

src/i18n/translations/pl.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
"session_expired": {
1010
"description": "Spróbuj zalogować się ponownie",
1111
"title": "Twoja sesja wygasła"
12-
},
13-
"remove_account": {
14-
"description": "Czy na pewno chcesz usunąć swoje konto?",
15-
"title": "Uwaga!",
16-
"confirm": "Tak, usuń"
1712
}
1813
},
1914
"bottom_tabs": {
@@ -34,8 +29,7 @@
3429
"save": "Zapisz",
3530
"search": "Szukaj",
3631
"try_again_later": "Proszę spróbuj ponownie później",
37-
"try_again": "Spróbuj ponownie",
38-
"remove_account": "Usuń konto"
32+
"try_again": "Spróbuj ponownie"
3933
},
4034
"errors": {
4135
"invalid_email": "Niepoprawny adres e-mail",

src/screens/ProfileScreen.tsx

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,75 @@
1+
import { useAuthControllerDelete } from '@baca/api/query/auth/auth'
12
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'
34
import { useCallback, useTranslation, useUpdateProfileForm, useScreenOptions } from '@baca/hooks'
5+
import { signOut } from '@baca/store/auth'
6+
import { showErrorToast } from '@baca/utils'
47
import { useRouter } from 'expo-router'
58

69
export const ProfileScreen = () => {
710
const { t } = useTranslation()
811
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+
)
962

1063
useScreenOptions({
1164
title: t('navigation.screen_titles.profile'),
1265
})
1366

14-
const { control, errors, isSubmitting, setFocus, submit } = useUpdateProfileForm()
15-
1667
const focusLastNameInput = useCallback(() => setFocus('lastName'), [setFocus])
1768

1869
return (
1970
<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>
2373
<Box borderColor="utility.gray.300" borderBottomWidth={2} borderTopWidth={2} my={4} py={4}>
2474
<ControlledField.Input
2575
{...{ control, errors }}
@@ -73,6 +123,18 @@ export const ProfileScreen = () => {
73123
{t('common.save')}
74124
</Button>
75125
</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>
76138
</Box>
77139
)
78140
}

src/screens/SettingsScreen.tsx

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import { useAuthControllerDelete } from '@baca/api/query/auth/auth'
21
import { Version } from '@baca/components'
32
import { colorSchemesList } from '@baca/constants'
43
import { useColorScheme } from '@baca/contexts'
54
import { Spacer, Button, Center, Text, ScrollView } from '@baca/design-system'
65
import { useCallback, useScreenOptions, useTranslation } from '@baca/hooks'
76
import { signOut } from '@baca/store/auth'
8-
import { alert, noop, showErrorToast } from '@baca/utils'
7+
import { noop } from '@baca/utils'
98

109
export const SettingsScreen = (): JSX.Element => {
1110
const { t } = useTranslation()
1211
const { setColorSchemeSetting, colorSchemeSetting } = useColorScheme()
13-
const { mutateAsync: removeUserAccount, isLoading } = useAuthControllerDelete()
1412

1513
useScreenOptions({
1614
title: t('navigation.screen_titles.settings'),
@@ -23,28 +21,6 @@ export const SettingsScreen = (): JSX.Element => {
2321
[setColorSchemeSetting]
2422
)
2523

26-
const handleRemoveUserAccount = useCallback(async () => {
27-
alert(t('alert.remove_account.title'), t('alert.remove_account.description'), [
28-
{
29-
text: t('alert.remove_account.confirm'),
30-
onPress: async () => {
31-
try {
32-
await removeUserAccount()
33-
signOut()
34-
} catch {
35-
showErrorToast({
36-
description: t('errors.something_went_wrong'),
37-
})
38-
}
39-
},
40-
},
41-
{
42-
text: t('common.cancel'),
43-
style: 'destructive',
44-
},
45-
])
46-
}, [removeUserAccount, t])
47-
4824
return (
4925
<ScrollView mt={4}>
5026
<Center flex={1}>
@@ -64,9 +40,6 @@ export const SettingsScreen = (): JSX.Element => {
6440
<Button.SecondaryColor mt={8} size="lg" onPress={signOut}>
6541
{t('settings_screen.sign_out')}
6642
</Button.SecondaryColor>
67-
<Button mt={8} onPress={handleRemoveUserAccount} loading={isLoading}>
68-
{t('settings_screen.remove_account')}
69-
</Button>
7043
<Spacer y={10} />
7144
<Version onPress={noop} />
7245
</Center>

0 commit comments

Comments
 (0)