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)}>
)}