Skip to content

Commit

Permalink
Merge pull request #46 from binarapps/feat/remove-user-account
Browse files Browse the repository at this point in the history
Feat/remove user account
  • Loading branch information
MateuszRostkowski authored Apr 12, 2024
2 parents 294ec2d + ee5f453 commit c89b1e6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"session_expired": {
"description": "Try to log in again",
"title": "Your current session expired"
},
"remove_account": {
"description": "Are you sure you want to delete your account?",
"title": "Attention!",
"confirm": "Yes, delete"
}
},
"common": {
Expand All @@ -21,7 +26,8 @@
"save": "Save",
"search": "Search",
"try_again_later": "Please try again later",
"try_again": "Try again"
"try_again": "Try again",
"remove_account": "Remove account"
},
"errors": {
"invalid_email": "Niepoprawny adres e-mail",
Expand Down Expand Up @@ -219,7 +225,8 @@
"copy_push_token": "Copy push token",
"current_theme": "Current theme: {{theme}}",
"sign_out": "Sign out!",
"selected": " - selected"
"selected": " - selected",
"remove_account": "Remove account"
},
"sign_in_screen": {
"do_not_have_an_account": "Don't have an account?",
Expand Down
13 changes: 10 additions & 3 deletions src/i18n/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"session_expired": {
"description": "Spróbuj zalogować się ponownie",
"title": "Twoja sesja wygasła"
},
"remove_account": {
"description": "Czy na pewno chcesz usunąć swoje konto?",
"title": "Uwaga!",
"confirm": "Tak, usuń"
}
},
"common": {
Expand All @@ -21,7 +26,8 @@
"save": "Zapisz",
"search": "Szukaj",
"try_again_later": "Proszę spróbuj ponownie później",
"try_again": "Spróbuj ponownie"
"try_again": "Spróbuj ponownie",
"remove_account": "Usuń konto"
},
"errors": {
"invalid_email": "Niepoprawny adres e-mail",
Expand Down Expand Up @@ -60,7 +66,7 @@
"select": {},
"validation": {
"invalid_email_format": "Niepoprawny format adresu e-mail",
"password_min_1_special_char": "Musi zawierać co najmniej 1 znaj specjalny",
"password_min_1_special_char": "Musi zawierać co najmniej 1 znak specjalny",
"password_min_8_chars": "Musi składać się z co najmniej 8 znaków",
"passwords_does_not_match": "Wprowadzone hasła nie są identyczne",
"required": "Pole wymagane"
Expand Down Expand Up @@ -217,7 +223,8 @@
"settings_screen": {
"current_theme": "Current theme: {{theme}}",
"selected": " - wybrano",
"sign_out": "Wyloguj!"
"sign_out": "Wyloguj!",
"remove_account": "Usuń konto"
},
"sign_in_screen": {
"do_not_have_an_account": "Nie masz konta?",
Expand Down
29 changes: 28 additions & 1 deletion src/screens/SettingsScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { useAuthControllerDelete } from '@baca/api/query/auth/auth'
import { Version } from '@baca/components'
import { colorSchemesList } from '@baca/constants'
import { useColorScheme } from '@baca/contexts'
import { Spacer, Button, Center, Text, ScrollView } from '@baca/design-system'
import { useCallback, useScreenOptions, useTranslation } from '@baca/hooks'
import { signOut } from '@baca/store/auth'
import { noop } from '@baca/utils'
import { alert, noop, showErrorToast } from '@baca/utils'

export const SettingsScreen = (): JSX.Element => {
const { t } = useTranslation()
const { setColorSchemeSetting, colorSchemeSetting } = useColorScheme()
const { mutateAsync: removeUserAccount, isLoading } = useAuthControllerDelete()

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

const handleRemoveUserAccount = useCallback(async () => {
alert(t('alert.remove_account.title'), t('alert.remove_account.description'), [
{
text: t('alert.remove_account.confirm'),
onPress: async () => {
try {
await removeUserAccount()
signOut()
} catch {
showErrorToast({
description: t('errors.something_went_wrong'),
})
}
},
},
{
text: t('common.cancel'),
style: 'destructive',
},
])
}, [removeUserAccount, t])

return (
<ScrollView mt={4}>
<Center flex={1}>
Expand All @@ -40,6 +64,9 @@ export const SettingsScreen = (): JSX.Element => {
<Button.SecondaryColor mt={8} size="lg" onPress={signOut}>
{t('settings_screen.sign_out')}
</Button.SecondaryColor>
<Button mt={8} onPress={handleRemoveUserAccount} loading={isLoading}>
{t('settings_screen.remove_account')}
</Button>
<Spacer y={10} />
<Version onPress={noop} />
</Center>
Expand Down

0 comments on commit c89b1e6

Please sign in to comment.