Penalty Übersicht für Nutzer und Penalty-Log

This commit is contained in:
PxlLoewe
2025-06-21 22:05:16 -07:00
parent 4732ecb770
commit 93962a9ce4
15 changed files with 402 additions and 25 deletions

View File

@@ -0,0 +1,30 @@
import { ExclamationTriangleIcon } from "@radix-ui/react-icons";
import { prisma } from "@repo/db";
import { Error } from "_components/Error";
export default async function Page({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const penalty = await prisma.penalty.findUnique({
where: {
id: Number(id),
},
include: {
User: true,
CreatedUser: true,
},
});
if (!penalty) return <Error statusCode={404} title="User not found" />;
return (
<div className="grid grid-cols-6 gap-4">
<div className="col-span-full">
<p className="text-2xl font-semibold text-left flex items-center gap-2">
<ExclamationTriangleIcon className="w-5 h-5" />
Strafe #{penalty.id}
</p>
</div>
</div>
);
}

View File

@@ -0,0 +1,8 @@
"use server";
import { Prisma, prisma } from "@repo/db";
export const addPenalty = async (data: Prisma.PenaltyCreateInput) => {
return await prisma.penalty.create({
data,
});
};

View File

@@ -0,0 +1,15 @@
import { Error } from "_components/Error";
import { getServerSession } from "api/auth/[...nextauth]/auth";
export default async function ReportLayout({ children }: { children: React.ReactNode }) {
const session = await getServerSession();
if (!session) return <Error title="Nicht eingeloggt" statusCode={401} />;
const user = session.user;
if (!user?.permissions.includes("ADMIN_EVENT"))
return <Error title="Keine Berechtigung" statusCode={403} />;
return <>{children}</>;
}

View File

@@ -0,0 +1,88 @@
"use client";
import { Eye, LockKeyhole, RedoDot, Timer } from "lucide-react";
import Link from "next/link";
import { PaginatedTable } from "_components/PaginatedTable";
import { Penalty, PenaltyType, Report, User } from "@repo/db";
import { ColumnDef } from "@tanstack/react-table";
import { formatDistance } from "date-fns";
import { de } from "date-fns/locale";
export default function ReportPage() {
return (
<PaginatedTable
prismaModel="penalty"
include={{
CreatedUser: true,
Report: true,
}}
columns={
[
{
accessorKey: "type",
header: "Typ",
cell: ({ row }) => {
switch (row.getValue("type") as PenaltyType) {
case "KICK":
return (
<div className="text-warning flex gap-3">
<RedoDot />
Kick
</div>
);
case "TIME_BAN": {
const length = formatDistance(
new Date(row.original.timestamp),
new Date(row.original.until || Date.now()),
{ locale: de },
);
return (
<div className="text-warning flex gap-3">
<Timer />
Zeit Sperre ({length})
</div>
);
}
case "BAN":
return (
<div className="text-error flex gap-3">
<LockKeyhole /> Bann
</div>
);
}
},
},
{
accessorKey: "CreatedUser",
header: "Bestraft durch",
cell: ({ row }) => {
const user = row.getValue("CreatedUser") as User;
return `${user.firstname} ${user.lastname} (${user.publicId})`;
},
},
{
accessorKey: "timestamp",
header: "Time",
cell: ({ row }) => new Date(row.getValue("timestamp")).toLocaleString(),
},
{
accessorKey: "actions",
header: "Actions",
cell: ({ row }) => {
const report = row.original.Report;
if (!report[0]) return null;
return (
<Link href={`/admin/report/${report[0].id}`}>
<button className="btn btn-sm btn-outline btn-info flex items-center gap-2">
<Eye className="w-4 h-4" />
Report Anzeigen
</button>
</Link>
);
},
},
] as ColumnDef<Penalty & { Report: Report[] }>[]
}
/>
);
}