import { formatDate } from "@/lib/format-date"; import Link from "next/link"; import { getTranslations } from "next-intl/server"; import { dismissApplication } from "@/actions/admin-applications"; import { StatusCard } from "@/components/admin/dashboard"; import { prisma } from "@/lib/prisma"; import { redirect } from "next/navigation"; import { canAccess, getAdminContext, PERMS } from "@/lib/permissions"; export const dynamic = "force-dynamic"; type ApplicationRow = { id: bigint; userId: number; rankId: number; content: string; createdAt: Date | null; }; export default async function AdminApplications() { const { session, permissions } = await getAdminContext(); if (!canAccess(permissions, PERMS.USERS_VIEW, session.user.rank)) { redirect("/admin"); } const t = await getTranslations("pages.admin.applications"); let applications: ApplicationRow[]; try { applications = await prisma.websiteStaffApplications.findMany({ orderBy: { createdAt: "desc" }, take: 100, }); } catch { applications = []; } // Resolve applicant usernames (no relation defined on the model). const userMap = new Map(); if (applications.length > 0) { try { const ids = Array.from(new Set(applications.map((a) => a.userId))); const users = await prisma.user.findMany({ where: { id: { in: ids } }, select: { id: true, username: true }, }); for (const u of users) userMap.set(u.id, u.username); } catch { // no DB — fall back to raw ids } } return (
0 ? "warn" : "ok"} icon="📨" />

{t("applicationsTitle", { count: applications.length })}

{applications.length === 0 ? (
{t("noApplications")}
) : (
{applications.map((a) => { const username = userMap.get(a.userId); return (

{username ? ( {username} ) : ( t("userNumber", { id: a.userId }) )}

{t("rankLabel", { rank: a.rankId })}

{formatDate(a.createdAt, "datetime", "—")}

{a.content}

); })}
)}
); }