// WARNING: this code is quite trash "use client"; import Image from "next/image"; import { useState } from "react"; import { Icon } from "@iconify/react"; import { Prisma, PunishmentType } from "@prisma/client"; import SubmitButton from "../submit-button"; import PunishmentDeletionDialog from "./punishment-deletion-dialog"; interface ApiResponse { success: boolean; name: string; username: string; image: string; createdAt: string; punishments: Prisma.PunishmentGetPayload<{ include: { violatingMiis: true; }; }>[]; } interface MiiList { id: number; reason: string; } export default function Punishments() { const [userId, setUserId] = useState(-1); const [user, setUser] = useState(); const [type, setType] = useState("WARNING"); const [duration, setDuration] = useState(1); const [notes, setNotes] = useState(""); const [reasons, setReasons] = useState(""); const [miiList, setMiiList] = useState([]); const [newMii, setNewMii] = useState({ id: 0, reason: "", }); const [error, setError] = useState(undefined); const addMiiToList = () => { if (newMii.id && newMii.reason) { setMiiList([...miiList, { ...newMii, id: Number(newMii.id) }]); setNewMii({ id: 0, reason: "" }); } }; const removeMiiFromList = (index: number) => { setMiiList(miiList.filter((_, i) => i !== index)); }; const handleLookup = async () => { const response = await fetch(`/api/admin/lookup?id=${userId}`); const data = await response.json(); setUser(data); }; const handleSubmit = async () => { // todo: delete punishments const response = await fetch(`/api/admin/punish?id=${userId}`, { method: "POST", body: JSON.stringify({ type, duration, notes, reasons: reasons.split(","), miiReasons: miiList, }), }); if (!response.ok) { const { error } = await response.json(); setError(error); } // Set all inputs to empty/default setType("WARNING"); setDuration(1); setNotes(""); setReasons(""); setMiiList([]); setNewMii({ id: 0, reason: "" }); setError(""); await handleLookup(); }; return (
setUserId(Number(e.target.value))} className="pill input w-full max-w-lg" />
{user && (
Profile picture

{user.name}

@{user.username}

Created:{" "} {new Date(user.createdAt).toLocaleString("en-GB", { day: "2-digit", month: "long", year: "numeric", hour: "2-digit", minute: "2-digit", second: "2-digit", timeZone: "UTC", })}{" "} UTC


{user.punishments.length === 0 ? (

No punishments found.

) : ( <> {user.punishments.map((punishment) => (
{punishment.type}
{new Date(punishment.createdAt).toLocaleDateString("en-GB", { day: "2-digit", month: "short", year: "numeric" })}

Notes: {punishment.notes}

{punishment.type !== "WARNING" && (

Expires:{" "} {punishment.expiresAt ? new Date(punishment.expiresAt).toLocaleDateString("en-GB", { day: "2-digit", month: "short", year: "numeric" }) : "Never"}

)} {punishment.type !== "PERM_EXILE" && (

Returned: {JSON.stringify(punishment.returned)}

)}

Reasons:

    {punishment.reasons.map((reason, index) => (
  • {reason}
  • ))}

Mii Reasons:

    {punishment.violatingMiis.map((mii) => (
  • {mii.miiId}: {mii.reason}
  • ))}
))} )}
{/* Punishment type */}

Punishment Type

{/* Punishment duration */} {type === "TEMP_EXILE" && ( <>

Duration

)} {/* Punishment notes */}

Notes