Skip to main content

useReport

Location: src/hooks/useReport.js

Overview

Provides functionality for submitting reports about content or user behavior. Integrates with the useRateLimit hook to enforce rate limits on report submissions. Includes a predefined list of report reason categories and calls the submit_report Supabase RPC function.

Exports

REPORT_REASONS

A constant array of report reason options:

ValueLabel
spamSpam or misleading content
harassmentHarassment or bullying
hate_speechHate speech or discrimination
inappropriate_contentInappropriate or explicit content
impersonationImpersonation or fake account
self_harmSelf-harm or suicide content
violenceViolence or threats
privacy_violationPrivacy violation
copyrightCopyright infringement
otherOther

useReport

function useReport(): {
submitReport: (options: {
reportedType: string,
reportedId: string,
reportedUserId: string,
reason: string,
details?: string
}) => Promise<{ success: boolean, reportId?: string, error?: string, rateLimited?: boolean }>,
isSubmitting: boolean,
error: string | null,
rateLimitError: string | null,
clearError: () => void,
REPORT_REASONS: Array<{ value: string, label: string }>
}

Parameters

This hook takes no parameters.

Return Value

PropertyTypeDescription
submitReport(options) => Promise<Result>Submit a report. Checks rate limits, calls submit_report RPC, and records the action.
isSubmittingbooleanWhether a report is being submitted
errorstring | nullError message if submission failed
rateLimitErrorstring | nullRate limit error message if submissions are throttled
clearError() => voidClear both error and rate limit error state
REPORT_REASONSArrayThe predefined list of report reasons

Usage

import { useReport, REPORT_REASONS } from '../hooks/useReport';

function ReportDialog({ postId, postUserId, onClose }) {
const { submitReport, isSubmitting, error, clearError } = useReport();
const [reason, setReason] = useState('');
const [details, setDetails] = useState('');

const handleSubmit = async () => {
const result = await submitReport({
reportedType: 'post',
reportedId: postId,
reportedUserId: postUserId,
reason,
details
});

if (result.success) {
onClose();
}
};

return (
<div>
<select value={reason} onChange={(e) => setReason(e.target.value)}>
{REPORT_REASONS.map(r => (
<option key={r.value} value={r.value}>{r.label}</option>
))}
</select>
<textarea value={details} onChange={(e) => setDetails(e.target.value)} />
{error && <p className="error">{error}</p>}
<button onClick={handleSubmit} disabled={isSubmitting}>Submit Report</button>
</div>
);
}

Notes

  • Rate limits are checked before submission and also handled if the server returns a rate limit error.
  • Duplicate reports (same user reporting the same content) are detected via a unique constraint (error code 23505).
  • Users cannot report their own content.
  • The details field is trimmed before submission; empty strings are sent as null.

Last updated: 2026-02-07