Edit User
++ Update user account and player association. +
+diff --git a/src/app/admin/users/[id]/edit/page.tsx b/src/app/admin/users/[id]/edit/page.tsx new file mode 100644 index 0000000..85b425e --- /dev/null +++ b/src/app/admin/users/[id]/edit/page.tsx @@ -0,0 +1,81 @@ +import { prisma } from "@/lib/prisma" +import Navigation from "@/components/Navigation" +import Link from "next/link" +import { redirect } from "next/navigation" +import { hasRole } from "@/lib/permissions" +import EditUserForm from "@/app/admin/users/components/EditUserForm" + +export const dynamic = "force-dynamic"; + +export default async function EditUserPage({ + params, +}: { + params: { id: string }; +}) { + // Check permissions + const permission = await hasRole("club_admin"); + if (!permission.allowed) { + redirect("/auth/login"); + } + + const { id } = params; + + // Get user info + const user = await prisma.user.findUnique({ + where: { id }, + include: { + player: true, + }, + }); + + if (!user) { + redirect("/admin/users"); + } + + // Get all players without associated users (excluding the current user's player) + const availablePlayers = await prisma.player.findMany({ + where: { + OR: [ + { user: null }, + { id: user.playerId || -1 }, // Include the currently associated player if any + ], + }, + orderBy: { name: "asc" }, + }); + + return ( +
+ Update user account and player association. +
++ Create a new user account and optionally associate it with a player. +
++ Create users and associate them with players. +
+| + Email + | ++ Name + | ++ Role + | ++ Associated Player + | ++ Created + | ++ Actions + | +
|---|---|---|---|---|---|
| + {user.email} + | ++ {user.name || "-"} + | ++ + {user.role} + + | ++ {user.player ? ( + + {user.player.name} + + ) : ( + Not assigned + )} + | ++ {new Date(user.createdAt).toLocaleDateString()} + | +
+
+
+ Edit
+
+
+ |
+
+ The following players exist but don't have an associated user account. +
+