- Remove production DB dump (db_backup_*.sql) and update.log from git tracking - Add DB backups to .gitignore - Replace all console.log/console.error with structured logger module - Translate Dutch error messages to English (link-discord.ts) - Remove dead code blocks (register-form.tsx false && pattern) - Add ESLint flat config with TypeScript, React, Next.js, jsx-a11y, and security plugins - Add Prettier config - Add eslint-plugin-security for security-aware linting - Fix all 119+ ESLint warnings across the codebase: - Resolve security/detect-object-injection with safe access patterns - Resolve security/detect-non-literal-fs-filename with path traversal validation - Replace <img> with next/image <Image> component - Remove unused variables and imports - Replace non-null assertions with proper type guards - Replace <a> with <Link> for internal navigation - Use next/script Script component for external scripts - Fix setState-in-useEffect anti-patterns (navbar-color-picker, logo-generator, theme-switcher) - Add lint and format scripts to package.json All checks: typecheck ✓, tests 58/58 ✓, lint 0 errors 0 warnings ✓
109 lines
4.0 KiB
TypeScript
109 lines
4.0 KiB
TypeScript
import Link from "next/link";
|
|
import { ClipboardList } from "lucide-react";
|
|
import { dismissApplication } from "@/actions/admin-applications";
|
|
import { StatusCard } from "@/components/admin/dashboard";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { getTranslations } from "next-intl/server";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
type ApplicationRow = {
|
|
id: bigint;
|
|
userId: number;
|
|
rankId: number;
|
|
content: string;
|
|
createdAt: Date | null;
|
|
};
|
|
|
|
function formatDate(d: Date | null): string {
|
|
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "—";
|
|
}
|
|
|
|
export default async function AdminApplications() {
|
|
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<number, string>();
|
|
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 (
|
|
<main>
|
|
<div className="flex items-center gap-3 mb-6">
|
|
<div className="w-10 h-10 rounded-xl bg-gradient-to-br from-[var(--color-primary)]/20 to-[var(--color-primary)]/5 grid place-items-center">
|
|
<ClipboardList size={20} className="text-[var(--color-primary)]" />
|
|
</div>
|
|
<div>
|
|
<h1 className="m-0 text-xl font-extrabold text-[var(--color-text)]">{t("title")}</h1>
|
|
<p className="m-0 text-xs text-[var(--color-text-muted)] mt-0.5">{t("subtitle")}</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-3.5 mb-6">
|
|
<StatusCard
|
|
label={t("pending")}
|
|
value={applications.length}
|
|
state={applications.length > 0 ? "warn" : "ok"}
|
|
icon="📨"
|
|
/>
|
|
</div>
|
|
|
|
<section className="mt-6">
|
|
<h2 className="admin-section-title">{t("applicationsTitle", { count: applications.length })}</h2>
|
|
{applications.length === 0 ? (
|
|
<div className="admin-empty">{t("noApplications")}</div>
|
|
) : (
|
|
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
|
{applications.map((a) => {
|
|
const username = userMap.get(a.userId);
|
|
return (
|
|
<article key={String(a.id)} className="admin-card p-3">
|
|
<div className="flex items-baseline justify-between gap-2 mb-1">
|
|
<h3 className="m-0 text-sm font-semibold text-[var(--color-text)]">
|
|
{username ? (
|
|
<Link href={`/admin/users/${a.userId}`}>{username}</Link>
|
|
) : (
|
|
<>{t("userNumber", { id: a.userId })}</>
|
|
)}
|
|
</h3>
|
|
<span className="inline-block text-[0.72rem] font-bold px-2 py-0.5 rounded-full bg-[var(--color-primary)]/18 text-[var(--color-text)]">{t("rankLabel", { rank: a.rankId })}</span>
|
|
</div>
|
|
<p className="text-xs text-gray-500 dark:text-gray-400 m-0 mb-2">
|
|
{formatDate(a.createdAt)}
|
|
</p>
|
|
<p className="text-sm text-[var(--color-text)] whitespace-pre-wrap m-0 mb-3">{a.content}</p>
|
|
<form action={dismissApplication}>
|
|
<input type="hidden" name="id" value={String(a.id)} />
|
|
<button type="submit" className="btn btn-danger">
|
|
{t("dismiss")}
|
|
</button>
|
|
</form>
|
|
</article>
|
|
);
|
|
})}
|
|
</div>
|
|
)}
|
|
</section>
|
|
</main>
|
|
);
|
|
}
|