import Link from "next/link"; import { notFound } from "next/navigation"; import { updateUser } from "@/actions/admin-user-edit"; import { requireStaff } from "@/lib/admin/guard"; import { User } from "lucide-react"; import { prisma } from "@/lib/prisma"; import { getTranslations } from "next-intl/server"; export const dynamic = "force-dynamic"; // users_currency.type values for the non-credits currencies (see send-currency.ts). const DUCKETS_TYPE = 0; const DIAMONDS_TYPE = 5; export default async function AdminUserEdit({ params, }: { params: Promise<{ id: string }>; }) { // Gate the page with the SAME helper the action re-checks. await requireStaff(); const { id } = await params; const t = await getTranslations("pages.admin.users.editForm"); const userId = Number(id); if (!Number.isInteger(userId) || userId <= 0) notFound(); let user: { id: number; username: string; mail: string | null; motto: string; look: string; rank: number; credits: number; pixels: number; points: number; } | null = null; let duckets = 0; let diamonds = 0; try { user = await prisma.user.findUnique({ where: { id: userId }, select: { id: true, username: true, mail: true, motto: true, look: true, rank: true, credits: true, pixels: true, points: true, }, }); if (user) { const currencies = await prisma.usersCurrency.findMany({ where: { userId, type: { in: [DUCKETS_TYPE, DIAMONDS_TYPE] } }, select: { type: true, amount: true }, }); for (const c of currencies) { if (c.type === DUCKETS_TYPE) duckets = c.amount; else if (c.type === DIAMONDS_TYPE) diamonds = c.amount; } } } catch { return ( ← {t("title")} {t("title")} {t("loadError")} ); } if (!user) notFound(); return ( ← {user.username} {t("title", { username: user.username })} {t("idLabel", { id: user.id })} {t("email")} {t("rank")} {t("motto")} {t("look")} {t("credits")} {t("pixels")} {t("points")} {t("duckets")} {t("diamonds")} {t("hint")} {t("save")} {t("cancel")} ); }
← {t("title")}
{t("loadError")}
← {user.username}
{t("idLabel", { id: user.id })}
{t("hint")}