This commit is contained in:
PxlLoewe
2025-06-23 19:33:00 -07:00
parent 65ea4640c3
commit dabcad2525
13 changed files with 294 additions and 292 deletions

View File

@@ -1,15 +1,13 @@
"use client";
import { penaltyColumns as penaltyColumns } from "(app)/admin/penalty/page";
import { editReport } from "(app)/admin/report/actions";
import { zodResolver } from "@hookform/resolvers/zod";
import { Report as IReport, Penalty, PenaltyType, Report, User } from "@repo/db";
import { Report as IReport, User } from "@repo/db";
import { ReportSchema, Report as IReportZod } from "@repo/db/zod";
import { ColumnDef } from "@tanstack/react-table";
import { PaginatedTable } from "_components/PaginatedTable";
import { Button } from "_components/ui/Button";
import { Switch } from "_components/ui/Switch";
import { formatDistance } from "date-fns";
import { de } from "date-fns/locale";
import { Eye, LockKeyhole, RedoDot, Shield, Timer, Trash } from "lucide-react";
import { Shield, Trash } from "lucide-react";
import { useSession } from "next-auth/react";
import Link from "next/link";
import { useRouter } from "next/navigation";
@@ -142,16 +140,6 @@ export const ReportPenalties = ({
Reviewer?: User | null;
};
}) => {
if (!report.penaltyId)
return (
<div className="card-body">
<h2 className="card-title">
<Shield className="w-5 h-5" /> Strafen zu diesem Report
</h2>
<p className="text-sm text-gray-600">Es wurden keine Strafen zu diesem Report erfasst.</p>
</div>
);
return (
<div className="card-body">
<h2 className="card-title">
@@ -164,76 +152,9 @@ export const ReportPenalties = ({
Report: true,
}}
filter={{
id: report.penaltyId,
reportId: report.id,
}}
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[] }>[]
}
columns={penaltyColumns}
/>
</div>
);