feat: add delete user functionality for site admins
This commit is contained in:
@@ -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>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user