Files
Arnaud 57c29f62b4 feat: user blocking and content reporting/flagging
- user_blocks table (composite PK), Block/Unblock button on profiles.
  Blocking severs any existing follow relationship both ways and
  prevents the blocked party from following, commenting on the
  blocker's recipes, or the blocker from seeing their comments.
- reports table (recipe/comment/user targets, pending/reviewed/
  dismissed status). ReportButton on comments, admin review queue at
  /admin/reports with dismiss/mark-reviewed actions, audit-logged.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-03 22:09:14 +02:00

68 lines
2.2 KiB
TypeScript

"use client";
import { useRouter } from "next/navigation";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
type Report = {
id: string;
targetType: "recipe" | "comment" | "user";
targetId: string;
reason: string;
createdAt: string;
reporterName: string;
reporterEmail: string;
};
export function ReportsQueue({ reports }: { reports: Report[] }) {
const router = useRouter();
async function resolve(id: string, status: "reviewed" | "dismissed") {
const res = await fetch(`/api/v1/admin/reports/${id}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ status }),
});
if (!res.ok) {
toast.error("Failed to update report");
return;
}
toast.success(status === "reviewed" ? "Marked reviewed" : "Dismissed");
router.refresh();
}
if (reports.length === 0) {
return <p className="text-muted-foreground text-sm">No pending reports.</p>;
}
return (
<div className="space-y-3">
{reports.map((r) => (
<div key={r.id} className="rounded-lg border p-4 space-y-2">
<div className="flex items-start justify-between gap-4">
<div className="space-y-1">
<div className="flex items-center gap-2">
<Badge variant="outline" className="capitalize">{r.targetType}</Badge>
<span className="text-xs text-muted-foreground font-mono">{r.targetId}</span>
</div>
<p className="text-sm">{r.reason}</p>
<p className="text-xs text-muted-foreground">
Reported by {r.reporterName} ({r.reporterEmail}) · {new Date(r.createdAt).toLocaleString()}
</p>
</div>
<div className="flex gap-2 shrink-0">
<Button size="sm" variant="outline" onClick={() => { void resolve(r.id, "dismissed"); }}>
Dismiss
</Button>
<Button size="sm" onClick={() => { void resolve(r.id, "reviewed"); }}>
Mark reviewed
</Button>
</div>
</div>
</div>
))}
</div>
);
}