From 64e7fcbcc7e657abeec7cd5704ecd8e3b738ec2d Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Tue, 26 Sep 2023 13:51:41 +0100 Subject: [PATCH] Added the ability to delete a user --- src/pages/(admin)/Lists/UserList.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pages/(admin)/Lists/UserList.tsx b/src/pages/(admin)/Lists/UserList.tsx index cff69b2f..dd34003d 100644 --- a/src/pages/(admin)/Lists/UserList.tsx +++ b/src/pages/(admin)/Lists/UserList.tsx @@ -16,6 +16,20 @@ const columnHelper = createColumnHelper(); export default function UserList({user}: {user: User}) { const {users, reload} = useUsers(); + const deleteAccount = (user: User) => { + if (!confirm(`Are you sure you want to delete ${user.name}'s account?`)) return; + + axios + .delete<{ok: boolean}>(`/api/user?id=${user.id}`) + .then(() => { + toast.success("User deleted successfully!"); + reload(); + }) + .catch(() => { + toast.error("Something went wrong!", {toastId: "delete-error"}); + }); + }; + const updateAccountType = (user: User, type: Type) => { if (!confirm(`Are you sure you want to update ${user.name}'s account from ${capitalize(user.type)} to ${capitalize(type)}?`)) return; @@ -128,7 +142,7 @@ export default function UserList({user}: {user: User}) { )} {PERMISSIONS.deleteUser[row.original.type].includes(user.type) && ( -
+
deleteAccount(row.original)}>
)}