feat: add admin reports page for managing user reports
- Introduced a new admin reports page at `/admin/reports`. - Added functionality to fetch, display, and update the status of user reports. - Integrated status management with options to review, resolve, and dismiss reports.
This commit is contained in:
191
frontend/src/app/(dashboard)/admin/reports/page.tsx
Normal file
191
frontend/src/app/(dashboard)/admin/reports/page.tsx
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import {
|
||||||
|
CheckCircle,
|
||||||
|
XCircle,
|
||||||
|
AlertCircle,
|
||||||
|
MoreHorizontal,
|
||||||
|
ArrowLeft,
|
||||||
|
} from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from "@/components/ui/card";
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu";
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table";
|
||||||
|
import { adminService } from "@/services/admin.service";
|
||||||
|
import { ReportStatus, type Report } from "@/services/report.service";
|
||||||
|
|
||||||
|
export default function AdminReportsPage() {
|
||||||
|
const [reports, setReports] = useState<Report[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
const fetchReports = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const data = await adminService.getReports();
|
||||||
|
setReports(data);
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Erreur lors du chargement des signalements.");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchReports();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleUpdateStatus = async (reportId: string, status: ReportStatus) => {
|
||||||
|
try {
|
||||||
|
await adminService.updateReportStatus(reportId, status);
|
||||||
|
toast.success("Statut mis à jour.");
|
||||||
|
fetchReports();
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Erreur lors de la mise à jour du statut.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getStatusBadge = (status: ReportStatus) => {
|
||||||
|
switch (status) {
|
||||||
|
case ReportStatus.PENDING:
|
||||||
|
return <Badge variant="outline">En attente</Badge>;
|
||||||
|
case ReportStatus.REVIEWED:
|
||||||
|
return <Badge variant="secondary">Examiné</Badge>;
|
||||||
|
case ReportStatus.RESOLVED:
|
||||||
|
return <Badge variant="success">Résolu</Badge>;
|
||||||
|
case ReportStatus.DISMISSED:
|
||||||
|
return <Badge variant="destructive">Rejeté</Badge>;
|
||||||
|
default:
|
||||||
|
return <Badge variant="default">{status}</Badge>;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-1 space-y-8 p-4 pt-6 md:p-8">
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
|
<Button variant="ghost" size="icon" asChild>
|
||||||
|
<Link href="/admin">
|
||||||
|
<ArrowLeft className="h-4 w-4" />
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
<h2 className="text-3xl font-bold tracking-tight">Signalements</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Liste des signalements</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Gérez les signalements de contenu inapproprié.
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>Raison</TableHead>
|
||||||
|
<TableHead>Description</TableHead>
|
||||||
|
<TableHead>Statut</TableHead>
|
||||||
|
<TableHead>Date</TableHead>
|
||||||
|
<TableHead className="text-right">Actions</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{loading ? (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={5} className="text-center py-8">
|
||||||
|
Chargement...
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
) : reports.length === 0 ? (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={5} className="text-center py-8">
|
||||||
|
Aucun signalement trouvé.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
) : (
|
||||||
|
reports.map((report) => (
|
||||||
|
<TableRow key={report.uuid}>
|
||||||
|
<TableCell className="font-medium capitalize">
|
||||||
|
{report.reason}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="max-w-xs truncate">
|
||||||
|
{report.description || "-"}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{getStatusBadge(report.status)}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{new Date(report.createdAt).toLocaleDateString()}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="ghost" size="icon">
|
||||||
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() =>
|
||||||
|
handleUpdateStatus(report.uuid, ReportStatus.REVIEWED)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<AlertCircle className="h-4 w-4 mr-2" />
|
||||||
|
Marquer comme examiné
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() =>
|
||||||
|
handleUpdateStatus(report.uuid, ReportStatus.RESOLVED)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<CheckCircle className="h-4 w-4 mr-2" />
|
||||||
|
Marquer comme résolu
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() =>
|
||||||
|
handleUpdateStatus(report.uuid, ReportStatus.DISMISSED)
|
||||||
|
}
|
||||||
|
className="text-destructive"
|
||||||
|
>
|
||||||
|
<XCircle className="h-4 w-4 mr-2" />
|
||||||
|
Rejeter
|
||||||
|
</DropdownMenuItem>
|
||||||
|
{report.contentId && (
|
||||||
|
<DropdownMenuItem asChild>
|
||||||
|
<Link href={`/meme/${report.contentId}`}>
|
||||||
|
Voir le contenu
|
||||||
|
</Link>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
)}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user