Penalty Übersicht für Nutzer und Penalty-Log
This commit is contained in:
30
apps/hub/app/(app)/admin/penalty/[id]/page.tsx
Normal file
30
apps/hub/app/(app)/admin/penalty/[id]/page.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
8
apps/hub/app/(app)/admin/penalty/actions.ts
Normal file
8
apps/hub/app/(app)/admin/penalty/actions.ts
Normal 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,
|
||||
});
|
||||
};
|
||||
15
apps/hub/app/(app)/admin/penalty/layout.tsx
Normal file
15
apps/hub/app/(app)/admin/penalty/layout.tsx
Normal 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}</>;
|
||||
}
|
||||
88
apps/hub/app/(app)/admin/penalty/page.tsx
Normal file
88
apps/hub/app/(app)/admin/penalty/page.tsx
Normal 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[] }>[]
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user