"use client"; import { HugeiconsIcon } from "@hugeicons/react"; import { Cancel01Icon, CheckmarkCircle01Icon, Flag01Icon } from "@hugeicons/core-free-icons"; import { useRouter } from "next/navigation"; import { useEffect, useRef, useState } from "react"; import type { Incident, IncidentStatus } from "@/types"; const actions = [ { status: "reviewed", label: "Flag as Reviewed", icon: CheckmarkCircle01Icon }, { status: "dismissed", label: "Dismiss (Mark Safe)", icon: Cancel01Icon }, { status: "escalated", label: "Escalate to Admin", icon: Flag01Icon } ] as const; export function IncidentReviewPanel({ incident }: { incident: Incident }) { const router = useRouter(); const [note, setNote] = useState(incident.review_note ?? ""); const [isSubmitting, setSubmitting] = useState(null); const [feedback, setFeedback] = useState<{ kind: "success" | "error"; message: string } | null>(null); const refreshTimer = useRef(null); useEffect(() => { return () => { if (refreshTimer.current) { window.clearTimeout(refreshTimer.current); } }; }, []); async function update(status: IncidentStatus) { setSubmitting(status); setFeedback(null); try { const response = await fetch(`/api/incidents/${incident.id}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ status, review_note: note || null }) }); const payload = (await response.json().catch(() => null)) as Partial & { error?: string } | null; if (!response.ok) { throw new Error(payload?.error ?? "Unable to update incident"); } const updatedStatus = payload?.status ?? status; const updatedNote = payload?.review_note; if (typeof updatedNote === "string" || updatedNote === null) { setNote(updatedNote ?? ""); } setFeedback({ kind: "success", message: `Incident marked ${updatedStatus}. Refreshing details...` }); if (refreshTimer.current) { window.clearTimeout(refreshTimer.current); } refreshTimer.current = window.setTimeout(() => router.refresh(), 1000); } catch (err) { setFeedback({ kind: "error", message: err instanceof Error ? err.message : "Unable to update incident" }); } finally { setSubmitting(null); } } return (

Moderator Decision Panel