Add admin Articles (CRUD) + Bans resources

- Articles: list / new / edit / delete (websiteArticles), unique-slug
  generation via slugify() (pure, unit-tested); staff-gated server actions.
- Bans: list active bans (ban_expire > now), create ban (writes the bans row +
  RCON disconnect) with type/duration/reason, lift ban; staff-gated actions.
- Admin nav extended (Articles, Bans).

Verified: tsc exit 0, vitest 48/48, next build exit 0 (7 /admin routes).
This commit is contained in:
Simo committed 2026-06-28 12:52:38 +02:00
1 parent 9f81096f05
commit 5861d9f1f5
9 files changed
+310 -1

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import Link from "next/link";
import { notFound } from "next/navigation";
import { deleteArticle, updateArticle } from "@/actions/admin-articles";
import { prisma } from "@/lib/prisma";
export const dynamic = "force-dynamic";
export default async function EditArticle({
params,
}: {
params: Promise<{ id: string }>;
}) {
const { id } = await params;
let article: Awaited<ReturnType<typeof prisma.websiteArticles.findUnique>> = null;
try {
article = await prisma.websiteArticles.findUnique({ where: { id: BigInt(id) } });
} catch {
notFound();
}
if (!article) notFound();
return (
<main>
<p className="muted">
<Link href="/admin/articles">← Articles</Link>
</p>
<h1>Edit article</h1>
<form action={updateArticle} className="card" style={{ display: "grid", gap: "0.6rem" }}>
<input type="hidden" name="id" value={String(article.id)} />
<input name="title" defaultValue={article.title} required />
<input name="image" defaultValue={article.image} placeholder="Image URL" />
<textarea name="shortStory" defaultValue={article.shortStory} rows={2} />
<textarea name="fullStory" defaultValue={article.fullStory} rows={10} />
<button type="submit">Save</button>
</form>
<form action={deleteArticle} style={{ marginTop: "1rem" }}>
<input type="hidden" name="id" value={String(article.id)} />
<button type="submit">Delete article</button>
</form>
</main>
);
}