From f26cbf2f650ef549a45dd65254e296476fc94820 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Tue, 31 Mar 2026 10:26:11 -0700 Subject: [PATCH] feat: add delete user functionality for site admins --- .../admin/users/components/UserActions.tsx | 46 +++++++++++++++++++ src/app/admin/users/page.tsx | 17 +++---- 2 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 src/app/admin/users/components/UserActions.tsx diff --git a/src/app/admin/users/components/UserActions.tsx b/src/app/admin/users/components/UserActions.tsx new file mode 100644 index 0000000..33cbb8b --- /dev/null +++ b/src/app/admin/users/components/UserActions.tsx @@ -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 ( +
+ + Edit + + {isSiteAdmin && userId !== currentUserId && ( + + )} +
+ ) +} diff --git a/src/app/admin/users/page.tsx b/src/app/admin/users/page.tsx index e363415..e3fb105 100644 --- a/src/app/admin/users/page.tsx +++ b/src/app/admin/users/page.tsx @@ -4,6 +4,7 @@ import Link from "next/link" import { redirect } from "next/navigation" import { getSession } from "@/lib/auth-simple" import { hasRole } from "@/lib/permissions" +import UserActions from "./components/UserActions" export const dynamic = "force-dynamic"; @@ -16,6 +17,9 @@ export default async function AdminUsersPage() { const session = await getSession(); const userId = session?.user?.id || session?.user?.userId; + + // Check if user is site_admin for delete permissions + const isSiteAdmin = await hasRole("site_admin"); // Fetch all users with their associated players const users = await prisma.user.findMany({ @@ -121,14 +125,11 @@ export default async function AdminUsersPage() { {new Date(user.createdAt).toLocaleDateString()} -
- - Edit - -
+ ))}