import { useState } from "react"; import { apiPost } from "../lib/api"; const CATEGORIES: { value: string; label: string }[] = [ { value: "bug", label: "Bug" }, { value: "feature", label: "Feature request" }, { value: "other", label: "Other" }, ]; function FlagIcon() { return ( ); } export function ReportIssueButton({ className }: { className?: string }) { const [open, setOpen] = useState(false); return ( <> setOpen(true)} className={className || "flex items-center gap-1.5 text-sm text-white/60 hover:text-white transition-colors"} title="Report an issue" > Report an issue {open && setOpen(false)} />} > ); } function ReportIssueModal({ onClose }: { onClose: () => void }) { const [category, setCategory] = useState("bug"); const [subject, setSubject] = useState(""); const [description, setDescription] = useState(""); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(""); const [done, setDone] = useState(false); const handleSubmit = async () => { if (!subject.trim() || !description.trim()) { setError("Please fill in both a subject and a description."); return; } setSubmitting(true); setError(""); try { await apiPost("/api/issues", { category, subject: subject.trim(), description: description.trim(), page_context: window.location.hash || window.location.pathname, }); setDone(true); } catch (e) { setError(e instanceof Error ? e.message : "Failed to submit — please try again."); } finally { setSubmitting(false); } }; return ( e.stopPropagation()} > {done ? ( Thanks — your report was sent. Close ) : ( <> Report an Issue Type {CATEGORIES.map((c) => ( setCategory(c.value)} className={`text-xs px-3 py-1.5 rounded-full border transition-colors ${ category === c.value ? "bg-[var(--color-primary)] text-white border-[var(--color-primary)]" : "text-[var(--color-text-muted)] border-[var(--color-border)] hover:border-[var(--color-primary)]/50" }`} > {c.label} ))} Subject setSubject(e.target.value)} placeholder="Short summary of the issue" className="input text-sm" /> Description setDescription(e.target.value)} placeholder="What happened, what did you expect, and any steps to reproduce it?" rows={4} className="input text-sm resize-none" /> {error && {error}} Cancel { void handleSubmit(); }} disabled={submitting} className="text-sm px-4 py-1.5 rounded-lg bg-[var(--color-primary)] text-white hover:bg-[var(--color-primary-light)] disabled:opacity-40 transition-colors" > {submitting ? "Sending…" : "Send report"} > )} ); }
Thanks — your report was sent.
{error}