From 7cce25a2618de0e75a0d02e6d1abdb00fb2553ba Mon Sep 17 00:00:00 2001 From: Jorrin Date: Sun, 21 Apr 2024 17:00:33 +0200 Subject: [PATCH] account deletion --- apps/expo/src/app/sync/login.tsx | 2 +- apps/expo/src/app/sync/register/account.tsx | 2 +- apps/expo/src/app/sync/register/confirm.tsx | 2 +- .../components/account/AccountInformation.tsx | 25 +++++- .../components/account/DeleteAccountAlert.tsx | 86 +++++++++++++++++++ 5 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 apps/expo/src/components/account/DeleteAccountAlert.tsx diff --git a/apps/expo/src/app/sync/login.tsx b/apps/expo/src/app/sync/login.tsx index 4381803..b267169 100644 --- a/apps/expo/src/app/sync/login.tsx +++ b/apps/expo/src/app/sync/login.tsx @@ -100,7 +100,7 @@ export default function Page() { Login {mutation.isError && ( - + {mutation.error.message} )} diff --git a/apps/expo/src/app/sync/register/account.tsx b/apps/expo/src/app/sync/register/account.tsx index b4dd052..4c6a3e9 100644 --- a/apps/expo/src/app/sync/register/account.tsx +++ b/apps/expo/src/app/sync/register/account.tsx @@ -102,7 +102,7 @@ export default function Page() { {errorMessage && ( - + {errorMessage} )} diff --git a/apps/expo/src/app/sync/register/confirm.tsx b/apps/expo/src/app/sync/register/confirm.tsx index 5e38b26..5f2ebf6 100644 --- a/apps/expo/src/app/sync/register/confirm.tsx +++ b/apps/expo/src/app/sync/register/confirm.tsx @@ -88,7 +88,7 @@ export default function Page() { {mutation.isError && ( - + {mutation.error.message} )} diff --git a/apps/expo/src/components/account/AccountInformation.tsx b/apps/expo/src/components/account/AccountInformation.tsx index 2ddae11..f298e42 100644 --- a/apps/expo/src/components/account/AccountInformation.tsx +++ b/apps/expo/src/components/account/AccountInformation.tsx @@ -1,6 +1,6 @@ import { useMemo } from "react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; -import { Spinner, Text, XStack, YStack } from "tamagui"; +import { H3, Spinner, Text, XStack, YStack } from "tamagui"; import { base64ToBuffer, @@ -17,6 +17,7 @@ import { MWCard } from "../ui/Card"; import { MWInput } from "../ui/Input"; import { MWSeparator } from "../ui/Separator"; import { Avatar } from "./Avatar"; +import { DeleteAccountAlert } from "./DeleteAccountAlert"; import { getExpoIconFromDbIcon } from "./UserIconPicker"; export function AccountInformation() { @@ -115,6 +116,11 @@ export function AccountInformation() { {sessions.isLoading && } + {sessions.isError && ( + + Error loading sessions + + )} {deviceListSorted.map((device) => ( @@ -136,6 +142,23 @@ export function AccountInformation() { ))} + + + + Actions + + + + +

Delete account

+ + This action is irreversible. All data will be deleted and + nothing can be recovered. + + +
+
+
); diff --git a/apps/expo/src/components/account/DeleteAccountAlert.tsx b/apps/expo/src/components/account/DeleteAccountAlert.tsx new file mode 100644 index 0000000..19f827c --- /dev/null +++ b/apps/expo/src/components/account/DeleteAccountAlert.tsx @@ -0,0 +1,86 @@ +import { useMutation } from "@tanstack/react-query"; +import { AlertDialog, XStack, YStack } from "tamagui"; + +import { deleteUser } from "@movie-web/api"; + +import { useAuth } from "~/hooks/useAuth"; +import { useAuthStore } from "~/stores/settings"; +import { MWButton } from "../ui/Button"; + +export function DeleteAccountAlert() { + const account = useAuthStore((state) => state.account); + const backendUrl = useAuthStore((state) => state.backendUrl); + const { logout } = useAuth(); + + const logoutMutation = useMutation({ + mutationKey: ["logout"], + mutationFn: logout, + }); + + const deleteAccountMutation = useMutation({ + mutationKey: ["deleteAccount"], + mutationFn: () => deleteUser(backendUrl, account!), + onSuccess: () => { + logoutMutation.mutate(); + }, + }); + + return ( + + + + Delete account + + + + + + + + Are you sure? + + This action is irreversible. All data will be deleted and nothing + can be recovered. + + + + + Cancel + + deleteAccountMutation.mutate()} + > + I am sure + + + + + + + ); +}