Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/remove user account #46

Merged
merged 6 commits into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/i18n/translations/en.json
Original file line number Diff line number Diff line change
@@ -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": {
@@ -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",
@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same string added to common. Please follow alphabetical order in this file

},
"sign_in_screen": {
"do_not_have_an_account": "Don't have an account?",
13 changes: 10 additions & 3 deletions src/i18n/translations/pl.json
Original file line number Diff line number Diff line change
@@ -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": {
@@ -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",
@@ -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"
@@ -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?",
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'),
@@ -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}>
@@ -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>
Loading