Files
thrilltrack-explorer/src/components/moderation/ReportButton.tsx
2025-10-31 12:03:22 +00:00

127 lines
3.7 KiB
TypeScript

import { useState } from 'react';
import { Flag, AlertTriangle } from 'lucide-react';
import { Button } from '@/components/ui/button';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { Textarea } from '@/components/ui/textarea';
import { Label } from '@/components/ui/label';
import { useAuth } from '@/hooks/useAuth';
import { useReportMutation } from '@/hooks/reports/useReportMutation';
interface ReportButtonProps {
entityType: 'review' | 'profile' | 'content_submission';
entityId: string;
className?: string;
}
const REPORT_TYPES = [
{ value: 'spam', label: 'Spam' },
{ value: 'inappropriate', label: 'Inappropriate Content' },
{ value: 'harassment', label: 'Harassment' },
{ value: 'fake_info', label: 'Fake Information' },
{ value: 'offensive', label: 'Offensive Language' },
];
export function ReportButton({ entityType, entityId, className }: ReportButtonProps) {
const [open, setOpen] = useState(false);
const [reportType, setReportType] = useState('');
const [reason, setReason] = useState('');
const { user } = useAuth();
const reportMutation = useReportMutation();
const handleSubmit = () => {
if (!user || !reportType) return;
reportMutation.mutate(
{ entityType, entityId, reportType, reason },
{
onSuccess: () => {
setOpen(false);
setReportType('');
setReason('');
},
}
);
};
if (!user) return null;
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button variant="ghost" size="sm" className={className}>
<Flag className="w-4 h-4 mr-2" />
Report
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<AlertTriangle className="w-5 h-5 text-destructive" />
Report Content
</DialogTitle>
<DialogDescription>
Help us maintain a safe community by reporting inappropriate content.
</DialogDescription>
</DialogHeader>
<div className="space-y-4">
<div>
<Label htmlFor="report-type">Reason for report</Label>
<Select value={reportType} onValueChange={setReportType}>
<SelectTrigger>
<SelectValue placeholder="Select a reason" />
</SelectTrigger>
<SelectContent>
{REPORT_TYPES.map((type) => (
<SelectItem key={type.value} value={type.value}>
{type.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div>
<Label htmlFor="reason">Additional details (optional)</Label>
<Textarea
id="reason"
placeholder="Provide additional context about your report..."
value={reason}
onChange={(e) => setReason(e.target.value)}
rows={3}
/>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => setOpen(false)}>
Cancel
</Button>
<Button
onClick={handleSubmit}
disabled={!reportType || reportMutation.isPending}
variant="destructive"
>
{reportMutation.isPending ? 'Submitting...' : 'Submit Report'}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}