"use client"; /** * ReportCommentModal — compact category + reason form for reporting a comment. * Controlled by the parent via `comment` (null = closed). Submits through the * comments API and toasts the outcome. */ import { useEffect, useState } from "react"; import { toast } from "sonner"; import { cn } from "@/lib/utils"; import { comments as commentsApi, SocialError, type Comment, type PostReportCategory, } from "@/lib/social"; const REPORT_CATEGORIES: { value: PostReportCategory; label: string }[] = [ { value: "spam", label: "Spam or misleading" }, { value: "harassment", label: "Harassment or bullying" }, { value: "misinformation", label: "Misinformation" }, { value: "inappropriate", label: "Inappropriate content" }, { value: "other", label: "Something else" }, ]; export function ReportCommentModal({ comment, onClose, }: { comment: Comment | null; onClose: () => void; }) { const [category, setCategory] = useState("spam"); const [reason, setReason] = useState(""); const [working, setWorking] = useState(false); useEffect(() => { if (comment) { setCategory("spam"); setReason(""); setWorking(false); } }, [comment]); if (!comment) return null; async function submit() { if (!comment) return; setWorking(true); try { await commentsApi.report(comment.id, category, reason.trim()); toast("Thanks — your report was submitted", { duration: 2500 }); onClose(); } catch (err) { toast.error( err instanceof SocialError ? err.message : "Could not submit report", { duration: 3000 }, ); } finally { setWorking(false); } } return (
!working && onClose()} aria-hidden />

Report comment

Reports are private and reviewed by our team.

{REPORT_CATEGORIES.map((c) => ( ))}