From b904f1ec0fe781a5d15464cec3b8a71ad2d0a5e8 Mon Sep 17 00:00:00 2001 From: Marcin-Ramotowski Date: Sun, 13 Apr 2025 18:51:58 +0200 Subject: [PATCH] Added possibility of deleting own account --- frontend/src/App.tsx | 2 + frontend/src/pages/DeleteAccount.tsx | 55 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 frontend/src/pages/DeleteAccount.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 09e9c1e..46f00a9 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -3,6 +3,7 @@ import Login from "./pages/Login"; import Tasks from "./pages/Tasks"; import Profile from "./pages/Profile"; import ChangePassword from "./pages/ChangePassword"; +import DeleteAccount from "./pages/DeleteAccount"; const App = () => { return ( @@ -12,6 +13,7 @@ const App = () => { } /> } /> } /> + } /> ); diff --git a/frontend/src/pages/DeleteAccount.tsx b/frontend/src/pages/DeleteAccount.tsx new file mode 100644 index 0000000..f1ab7dc --- /dev/null +++ b/frontend/src/pages/DeleteAccount.tsx @@ -0,0 +1,55 @@ +import { useNavigate, useParams } from "react-router-dom"; +import { useState } from "react"; +import api from "../api/api"; +import { logout } from "../api/auth"; + +const DeleteAccount = () => { + const navigate = useNavigate(); + const { id } = useParams(); + const [confirmation, setConfirmation] = useState(""); + const [error, setError] = useState(""); + + const handleDelete = async () => { + try { + await api.delete(`/users/${id}`); + await logout(); + navigate("/login"); + } catch (err: any) { + console.error(err); + setError("Wystąpił błąd podczas usuwania konta."); + } + }; + + return ( +
+

⚠️ Usuń konto

+

+ Tej operacji nie można cofnąć. Aby potwierdzić, wpisz USUŃ poniżej: +

+ + setConfirmation(e.target.value)} + className="border p-2 rounded w-full mb-4" + /> + + + + {error &&

{error}

} +
+ ); +}; + +export default DeleteAccount;