Wire report submission to API

cgen-2b431ae23c6c4a67a83b7c01fc6d3fb9
This commit is contained in:
Builder.io 2025-10-18 18:59:22 +00:00
parent 9424657211
commit ef88e717fd

View file

@ -1724,7 +1724,7 @@ export default function Community() {
); );
const handleReportSubmit = useCallback( const handleReportSubmit = useCallback(
(submitEvent: FormEvent<HTMLFormElement>) => { async (submitEvent: FormEvent<HTMLFormElement>) => {
submitEvent.preventDefault(); submitEvent.preventDefault();
const trimmedDetails = reportForm.details.trim(); const trimmedDetails = reportForm.details.trim();
@ -1740,12 +1740,31 @@ export default function Community() {
return; return;
} }
aethexToast.system( try {
"Report submitted. Our moderation team will review shortly.", const resp = await fetch("/api/moderation/reports", {
); method: "POST",
setReportForm({ reason: "", details: "" }); headers: { "Content-Type": "application/json" },
body: JSON.stringify({
reporter_id: (profile as any)?.id || null,
target_type: "other",
target_id: null,
reason: reportForm.reason,
details: trimmedDetails,
}),
});
if (!resp.ok) {
const msg = await resp.text();
throw new Error(msg || "Failed to submit report");
}
aethexToast.system(
"Report submitted. Our moderation team will review shortly.",
);
setReportForm({ reason: "", details: "" });
} catch (e: any) {
aethexToast.system(String(e?.message || e));
}
}, },
[reportForm], [reportForm, profile],
); );
if (isLoading) { if (isLoading) {