feat: add delete user functionality for site admins

This commit is contained in:
2026-03-31 10:26:11 -07:00
parent 2ed86dafe9
commit f26cbf2f65
2 changed files with 55 additions and 8 deletions
@@ -0,0 +1,46 @@
"use client"
import { useRouter } from "next/navigation"
interface UserActionsProps {
userId: string;
isSiteAdmin: boolean;
currentUserId: string;
}
export default function UserActions({ userId, isSiteAdmin, currentUserId }: UserActionsProps) {
const router = useRouter()
const handleDelete = async () => {
if (confirm("Are you sure you want to delete this user?")) {
const response = await fetch(`/api/admin/users/${userId}`, {
method: "DELETE",
});
if (response.ok) {
router.refresh();
} else {
const data = await response.json();
alert(data.error || "Failed to delete user");
}
}
}
return (
<div className="flex space-x-2">
<a
href={`/admin/users/${userId}/edit`}
className="text-blue-600 hover:text-blue-900"
>
Edit
</a>
{isSiteAdmin && userId !== currentUserId && (
<button
onClick={handleDelete}
className="text-red-600 hover:text-red-900"
>
Delete
</button>
)}
</div>
)
}