From 2aa56b59c72c7253584b704faf4237e9d19bf64f Mon Sep 17 00:00:00 2001 From: AINDUSTRIES Date: Sun, 27 Sep 2026 19:20:01 +0200 Subject: [PATCH] Added ability to delete account --- app/components/settings.tsx | 113 ++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 5 deletions(-) diff --git a/app/components/settings.tsx b/app/components/settings.tsx index e25f06d..3d313d2 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -9,8 +9,10 @@ import { Label, Typography, Spinner, + AlertDialog, + useOverlayState, } from "@heroui/react"; -import { useState, type Dispatch, type SetStateAction } from "react"; +import { useEffect, useState, type Dispatch, type SetStateAction } from "react"; import { useAuth } from "~/hooks/auth"; import { useNotification } from "~/hooks/notification"; @@ -21,9 +23,19 @@ export function Settings({ show: boolean; setShow: Dispatch>; }) { - const { user, update } = useAuth(); + const { user, update, logout } = useAuth(); const { notify } = useNotification(); const [loading, setLoading] = useState(false); + const [canClose, setCanClose] = useState(true); + const deleteState = useOverlayState(); + + useEffect(() => { + if (!deleteState.isOpen) { + setTimeout(() => { + setCanClose(true); + }, 100); + } + }, [deleteState]); const notifySucess = () => { notify( @@ -109,12 +121,40 @@ export function Settings({ setLoading(false); }; + const deleteAccount = async () => { + setLoading(true); + let ok = await fetch(`${import.meta.env.VITE_BASE_API_URL}/delete`, { + credentials: "include", + }) + .then((r) => r.ok) + .catch((e) => { + notify( + { + type: "danger", + loading: false, + title: "An error occured.", + message: `An error occured: ${e}`, + }, + 10000, + ); + }); + + if (ok) { + await logout(); + notifySucess(); + } + + setLoading(false); + deleteState.close(); + }; + return (
{ + if (!canClose) return false; setShow(false); return true; }} @@ -158,14 +198,32 @@ export function Settings({ image url. +
+ + + + + + +
); }