import { useState } from "react"; import { submitReport, type ContentReportCreate } from "../api/public-client"; interface ReportIssueModalProps { contentType: string; contentId?: string | null; contentTitle?: string | null; onClose: () => void; } const REPORT_TYPES = [ { value: "inaccurate", label: "Inaccurate content" }, { value: "missing_info", label: "Missing information" }, { value: "wrong_attribution", label: "Wrong attribution" }, { value: "formatting", label: "Formatting issue" }, { value: "other", label: "Other" }, ]; export default function ReportIssueModal({ contentType, contentId, contentTitle, onClose, }: ReportIssueModalProps) { const [reportType, setReportType] = useState("inaccurate"); const [description, setDescription] = useState(""); const [submitting, setSubmitting] = useState(false); const [submitted, setSubmitted] = useState(false); const [error, setError] = useState(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (description.trim().length < 10) { setError("Please provide at least 10 characters describing the issue."); return; } setSubmitting(true); setError(null); try { const body: ContentReportCreate = { content_type: contentType, content_id: contentId ?? null, content_title: contentTitle ?? null, report_type: reportType, description: description.trim(), page_url: window.location.href, }; await submitReport(body); setSubmitted(true); } catch (err) { setError( err instanceof Error ? err.message : "Failed to submit report", ); } finally { setSubmitting(false); } }; return (
e.stopPropagation()}> {submitted ? ( <>

Thank you

Your report has been submitted. We'll review it shortly.

) : ( <>

Report an issue

{contentTitle && (

About: {contentTitle}

)}