2026-05-31 00:41:34 +07:00
|
|
|
|
import { Siren } from "lucide-react";
|
2026-06-01 16:42:36 +07:00
|
|
|
|
import type { ViolatorStat } from "../../../shared/api/client";
|
2026-06-03 03:20:07 +07:00
|
|
|
|
import { cn } from "../../../shared/lib/utils";
|
2026-06-01 21:44:29 +07:00
|
|
|
|
import {
|
|
|
|
|
|
Badge,
|
|
|
|
|
|
Card,
|
|
|
|
|
|
CardContent,
|
|
|
|
|
|
CardDescription,
|
|
|
|
|
|
CardHeader,
|
|
|
|
|
|
CardTitle,
|
|
|
|
|
|
ScrollArea,
|
|
|
|
|
|
} from "../../../shared/ui";
|
2026-05-31 00:41:34 +07:00
|
|
|
|
|
|
|
|
|
|
interface ViolatorTableProps {
|
|
|
|
|
|
users: ViolatorStat[];
|
|
|
|
|
|
loading: boolean;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function ViolatorTable({ users, loading }: ViolatorTableProps) {
|
|
|
|
|
|
if (loading && !users?.length) {
|
|
|
|
|
|
return <LoadingBox />;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!users?.length) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Card>
|
|
|
|
|
|
<CardContent className="flex h-[260px] items-center justify-center text-sm text-muted-foreground">
|
|
|
|
|
|
Tidak ada pelanggaran terdeteksi.
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const maxScore = Math.max(...users.map((u) => u.violation_score), 1);
|
|
|
|
|
|
|
|
|
|
|
|
function dangerLabel(score: number) {
|
|
|
|
|
|
if (score >= 10) return { variant: "destructive" as const, text: "HIGH" };
|
|
|
|
|
|
if (score >= 5) return { variant: "warning" as const, text: "MED" };
|
|
|
|
|
|
return { variant: "secondary" as const, text: "LOW" };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Card>
|
|
|
|
|
|
<CardHeader className="pb-2">
|
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<CardTitle className="flex items-center gap-2 text-sm font-semibold">
|
2026-06-03 03:20:07 +07:00
|
|
|
|
<Siren className="h-4 w-4 text-accent" />
|
2026-05-31 00:41:34 +07:00
|
|
|
|
Pelanggar Terbanyak
|
|
|
|
|
|
</CardTitle>
|
|
|
|
|
|
<CardDescription className="text-xs">
|
2026-06-03 18:18:27 +07:00
|
|
|
|
Skor: flagged × 3 + warned. Flag terbanyak terakhir ditampilkan.
|
2026-05-31 00:41:34 +07:00
|
|
|
|
</CardDescription>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Badge variant="destructive">{users.length} pelanggar</Badge>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</CardHeader>
|
|
|
|
|
|
<CardContent className="p-0">
|
2026-06-03 18:18:27 +07:00
|
|
|
|
<ScrollArea className="max-h-[320px]">
|
2026-05-31 00:41:34 +07:00
|
|
|
|
<table className="w-full text-sm">
|
|
|
|
|
|
<thead>
|
2026-06-03 03:20:07 +07:00
|
|
|
|
<tr className="sticky top-0 z-10 bg-white border-b border-sky-100 text-left text-[10px] uppercase tracking-wider text-muted-foreground">
|
2026-05-31 00:41:34 +07:00
|
|
|
|
<th className="py-2 pl-4 pr-2 font-semibold">#</th>
|
|
|
|
|
|
<th className="py-2 pr-2 font-semibold">User</th>
|
|
|
|
|
|
<th className="py-2 pr-2 font-semibold text-right">Flagged</th>
|
2026-06-03 18:18:27 +07:00
|
|
|
|
<th className="py-2 pr-2 font-semibold text-right">Warned</th>
|
|
|
|
|
|
<th className="py-2 pr-2 font-semibold text-right">Skor</th>
|
|
|
|
|
|
<th className="py-2 pr-4 font-semibold">Flag</th>
|
2026-05-31 00:41:34 +07:00
|
|
|
|
</tr>
|
|
|
|
|
|
</thead>
|
2026-06-03 03:20:07 +07:00
|
|
|
|
<tbody className="divide-y divide-sky-50">
|
2026-05-31 00:41:34 +07:00
|
|
|
|
{users.map((user, i) => {
|
|
|
|
|
|
const danger = dangerLabel(user.violation_score);
|
|
|
|
|
|
return (
|
2026-06-01 21:44:29 +07:00
|
|
|
|
<tr
|
|
|
|
|
|
key={user.user_id}
|
2026-06-03 03:20:07 +07:00
|
|
|
|
className={cn(
|
|
|
|
|
|
"transition-colors border-l-2",
|
|
|
|
|
|
i % 2 === 0 ? "bg-white" : "bg-sky-50/20",
|
|
|
|
|
|
danger.variant === "destructive"
|
|
|
|
|
|
? "border-l-accent/60"
|
|
|
|
|
|
: danger.variant === "warning"
|
|
|
|
|
|
? "border-l-pink-300/60"
|
|
|
|
|
|
: "border-l-pink-200/40",
|
|
|
|
|
|
)}
|
2026-06-01 21:44:29 +07:00
|
|
|
|
>
|
2026-05-31 00:41:34 +07:00
|
|
|
|
<td className="py-1.5 pl-4 pr-2 font-mono text-[10px] text-muted-foreground tabular-nums">
|
|
|
|
|
|
{i + 1}
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td className="py-1.5 pr-2">
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
{user.avatar_url ? (
|
2026-06-01 21:44:29 +07:00
|
|
|
|
<img
|
|
|
|
|
|
src={user.avatar_url}
|
|
|
|
|
|
alt=""
|
2026-06-03 03:20:07 +07:00
|
|
|
|
className="h-6 w-6 rounded-full ring-2 ring-pink-100"
|
2026-06-01 21:44:29 +07:00
|
|
|
|
loading="lazy"
|
|
|
|
|
|
/>
|
2026-05-31 00:41:34 +07:00
|
|
|
|
) : (
|
2026-06-03 03:20:07 +07:00
|
|
|
|
<div className="flex h-6 w-6 items-center justify-center rounded-full bg-pink-100 text-[10px] font-bold text-accent">
|
2026-05-31 00:41:34 +07:00
|
|
|
|
{user.username.charAt(0).toUpperCase()}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-06-01 21:44:29 +07:00
|
|
|
|
<span className="max-w-[100px] truncate text-xs font-medium">
|
|
|
|
|
|
{user.username}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<Badge
|
|
|
|
|
|
variant={danger.variant}
|
|
|
|
|
|
className="text-[9px] px-1 py-0"
|
|
|
|
|
|
>
|
2026-05-31 00:41:34 +07:00
|
|
|
|
{danger.text}
|
|
|
|
|
|
</Badge>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</td>
|
2026-06-03 03:20:07 +07:00
|
|
|
|
<td className="py-1.5 pr-2 text-right font-mono text-xs text-accent tabular-nums">
|
2026-05-31 00:41:34 +07:00
|
|
|
|
{user.flagged_count}
|
|
|
|
|
|
</td>
|
2026-06-03 18:18:27 +07:00
|
|
|
|
<td className="py-1.5 pr-2 text-right font-mono text-xs text-yellow-600 tabular-nums">
|
|
|
|
|
|
{user.warned_count > 0 ? user.warned_count : "—"}
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td className="py-1.5 pr-2 text-right">
|
2026-05-31 00:41:34 +07:00
|
|
|
|
<div className="flex items-center justify-end gap-1.5">
|
2026-06-03 18:18:27 +07:00
|
|
|
|
<div className="h-1.5 w-12 overflow-hidden rounded-full bg-pink-50">
|
2026-05-31 00:41:34 +07:00
|
|
|
|
<div
|
|
|
|
|
|
className={cn(
|
|
|
|
|
|
"h-full rounded-full",
|
|
|
|
|
|
user.violation_score >= 10
|
2026-06-03 03:20:07 +07:00
|
|
|
|
? "bg-gradient-to-r from-accent to-pink-400"
|
2026-05-31 00:41:34 +07:00
|
|
|
|
: user.violation_score >= 5
|
2026-06-03 03:20:07 +07:00
|
|
|
|
? "bg-gradient-to-r from-pink-400 to-pink-300"
|
|
|
|
|
|
: "bg-gradient-to-r from-pink-300 to-pink-200",
|
2026-05-31 00:41:34 +07:00
|
|
|
|
)}
|
2026-06-01 21:44:29 +07:00
|
|
|
|
style={{
|
|
|
|
|
|
width: `${(user.violation_score / maxScore) * 100}%`,
|
|
|
|
|
|
}}
|
2026-05-31 00:41:34 +07:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2026-06-01 21:44:29 +07:00
|
|
|
|
<span className="font-mono text-xs font-bold tabular-nums">
|
|
|
|
|
|
{user.violation_score}
|
|
|
|
|
|
</span>
|
2026-05-31 00:41:34 +07:00
|
|
|
|
</div>
|
|
|
|
|
|
</td>
|
2026-06-03 18:18:27 +07:00
|
|
|
|
<td className="py-1.5 pr-4">
|
|
|
|
|
|
<div className="flex flex-wrap gap-1">
|
2026-06-03 18:27:41 +07:00
|
|
|
|
{user.worst_flags?.length > 0 ? (
|
|
|
|
|
|
user.worst_flags.slice(0, 3).map((flag) => (
|
|
|
|
|
|
<Badge
|
|
|
|
|
|
key={flag}
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
className="text-[8px] px-1 py-0 border-accent/30 text-accent"
|
|
|
|
|
|
>
|
|
|
|
|
|
{flag}
|
|
|
|
|
|
</Badge>
|
|
|
|
|
|
))
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<span className="text-[10px] text-muted-foreground">
|
|
|
|
|
|
—
|
|
|
|
|
|
</span>
|
|
|
|
|
|
)}
|
2026-06-03 18:18:27 +07:00
|
|
|
|
</div>
|
|
|
|
|
|
</td>
|
2026-05-31 00:41:34 +07:00
|
|
|
|
</tr>
|
|
|
|
|
|
);
|
|
|
|
|
|
})}
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
</ScrollArea>
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function LoadingBox() {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Card>
|
|
|
|
|
|
<CardContent className="flex h-[260px] items-center justify-center text-sm text-muted-foreground">
|
|
|
|
|
|
<span className="h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent" />
|
|
|
|
|
|
<span className="ml-2">Memuat data...</span>
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|