Revert "Merge pull request 'Complete Housekeeping migration and /ase cutover' (#52) from codex/housekeeping-complete into main"
This reverts commit488b6e57c4, reversing changes made tob506b4499a.
This commit is contained in:
1 parent
488b6e57c4
commit
b1ddda66ff
802 files changed
+61370
-76659
No files matched your search
@@ -0,0 +1,281 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
DoorOpen,
|
||||
Loader2,
|
||||
Megaphone,
|
||||
MessageSquare,
|
||||
Shield,
|
||||
Volume2,
|
||||
VolumeX,
|
||||
Zap,
|
||||
} from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import {
|
||||
broadcastAlert,
|
||||
quickAlert,
|
||||
quickKick,
|
||||
quickMute,
|
||||
quickRoomKick,
|
||||
quickUnmute,
|
||||
} from "@/actions/moderation";
|
||||
import { useConfirmDialog } from "@/components/admin/confirm-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { useServerAction } from "@/hooks/use-server-action";
|
||||
|
||||
export function ModActionsClient() {
|
||||
const { run, isPending } = useServerAction();
|
||||
const { confirm, dialog: confirmDialog } = useConfirmDialog();
|
||||
|
||||
const [userId, setUserId] = useState("");
|
||||
const [muteDuration, setMuteDuration] = useState("10");
|
||||
const [alertMessage, setAlertMessage] = useState("");
|
||||
const [roomId, setRoomId] = useState("");
|
||||
const [broadcastMsg, setBroadcastMsg] = useState("");
|
||||
|
||||
const uid = parseInt(userId, 10);
|
||||
const rid = parseInt(roomId, 10);
|
||||
|
||||
async function handleKick() {
|
||||
const ok = await confirm({
|
||||
title: "Kick user",
|
||||
description: `Disconnect user #${uid}?`,
|
||||
confirmLabel: "Kick",
|
||||
});
|
||||
if (!ok) return;
|
||||
run(() => quickKick({ userId: uid }), {
|
||||
successMessage: "User disconnected",
|
||||
});
|
||||
}
|
||||
|
||||
async function handleRoomKick() {
|
||||
const ok = await confirm({
|
||||
title: "Kick all from room",
|
||||
description: `Kick every user from room #${rid}?`,
|
||||
confirmLabel: "Kick all",
|
||||
});
|
||||
if (!ok) return;
|
||||
run(() => quickRoomKick({ roomId: rid }), {
|
||||
successMessage: "All users kicked from room",
|
||||
});
|
||||
}
|
||||
|
||||
async function handleHotelBroadcast() {
|
||||
const ok = await confirm({
|
||||
title: "Hotel-wide alert",
|
||||
description: "Send this alert to everyone in the hotel?",
|
||||
confirmLabel: "Send",
|
||||
variant: "default",
|
||||
});
|
||||
if (!ok) return;
|
||||
run(
|
||||
() =>
|
||||
broadcastAlert({
|
||||
message: broadcastMsg.trim(),
|
||||
type: "hotel",
|
||||
}),
|
||||
{
|
||||
successMessage: "Hotel alert sent!",
|
||||
onSuccess: () => setBroadcastMsg(""),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid gap-6 lg:grid-cols-2">
|
||||
{confirmDialog}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-sm flex items-center gap-2">
|
||||
<Zap className="h-4 w-4 text-[var(--admin-warning)]" />
|
||||
User Actions
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div>
|
||||
<span className="text-xs text-muted-foreground mb-1 block">
|
||||
User ID
|
||||
</span>
|
||||
<Input
|
||||
type="number"
|
||||
value={userId}
|
||||
onChange={(e) => setUserId(e.target.value)}
|
||||
placeholder="Enter user ID"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
disabled={isPending || !uid}
|
||||
onClick={handleKick}
|
||||
>
|
||||
{isPending ? (
|
||||
<Loader2 className="mr-1 h-3 w-3 animate-spin" />
|
||||
) : (
|
||||
<Zap className="mr-1 h-3 w-3" />
|
||||
)}
|
||||
Kick / Disconnect
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={isPending || !uid}
|
||||
onClick={() =>
|
||||
run(() => quickUnmute({ userId: uid }), {
|
||||
successMessage: "User unmuted",
|
||||
})
|
||||
}
|
||||
>
|
||||
<Volume2 className="mr-1 h-3 w-3" /> Unmute
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
max={1440}
|
||||
value={muteDuration}
|
||||
onChange={(e) => setMuteDuration(e.target.value)}
|
||||
className="w-24"
|
||||
placeholder="Min"
|
||||
/>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="flex-1"
|
||||
disabled={isPending || !uid || !parseInt(muteDuration, 10)}
|
||||
onClick={() =>
|
||||
run(
|
||||
() =>
|
||||
quickMute({
|
||||
userId: uid,
|
||||
duration: parseInt(muteDuration, 10),
|
||||
}),
|
||||
{
|
||||
successMessage: `Muted for ${muteDuration} min`,
|
||||
},
|
||||
)
|
||||
}
|
||||
>
|
||||
<VolumeX className="mr-1 h-3 w-3" /> Mute
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Textarea
|
||||
value={alertMessage}
|
||||
onChange={(e) => setAlertMessage(e.target.value)}
|
||||
placeholder="Alert message to user..."
|
||||
rows={2}
|
||||
className="resize-none text-xs"
|
||||
/>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="shrink-0 h-auto"
|
||||
disabled={isPending || !uid || !alertMessage.trim()}
|
||||
onClick={() => {
|
||||
run(
|
||||
() =>
|
||||
quickAlert({ userId: uid, message: alertMessage.trim() }),
|
||||
{
|
||||
successMessage: "Alert sent",
|
||||
onSuccess: () => setAlertMessage(""),
|
||||
},
|
||||
);
|
||||
}}
|
||||
>
|
||||
<MessageSquare className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-sm flex items-center gap-2">
|
||||
<DoorOpen className="h-4 w-4 text-[var(--admin-warning)]" />
|
||||
Room Actions
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div>
|
||||
<span className="text-xs text-muted-foreground mb-1 block">
|
||||
Room ID
|
||||
</span>
|
||||
<Input
|
||||
type="number"
|
||||
value={roomId}
|
||||
onChange={(e) => setRoomId(e.target.value)}
|
||||
placeholder="Enter room ID"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
className="w-full"
|
||||
disabled={isPending || !rid}
|
||||
onClick={handleRoomKick}
|
||||
>
|
||||
<Zap className="mr-1 h-3 w-3" /> Kick All From Room
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-sm flex items-center gap-2">
|
||||
<Megaphone className="h-4 w-4 text-primary" />
|
||||
Broadcast Alert
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<Textarea
|
||||
value={broadcastMsg}
|
||||
onChange={(e) => setBroadcastMsg(e.target.value)}
|
||||
placeholder="Type broadcast message..."
|
||||
rows={3}
|
||||
className="resize-none"
|
||||
/>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
disabled={isPending || !broadcastMsg.trim()}
|
||||
onClick={handleHotelBroadcast}
|
||||
>
|
||||
<Megaphone className="mr-1 h-3 w-3" /> Hotel Alert
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
disabled={isPending || !broadcastMsg.trim()}
|
||||
onClick={() => {
|
||||
run(
|
||||
() =>
|
||||
broadcastAlert({
|
||||
message: broadcastMsg.trim(),
|
||||
type: "staff",
|
||||
}),
|
||||
{
|
||||
successMessage: "Staff alert sent!",
|
||||
onSuccess: () => setBroadcastMsg(""),
|
||||
},
|
||||
);
|
||||
}}
|
||||
>
|
||||
<Shield className="mr-1 h-3 w-3" /> Staff Alert
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { ModActionsClient } from "./mod-actions-client";
|
||||
|
||||
export default async function QuickActionsPage() {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.MODERATION_EDIT, session.user.rank))
|
||||
redirect("/admin");
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<ModActionsClient />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,460 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
AlertTriangle,
|
||||
ArrowLeft,
|
||||
Ban,
|
||||
CheckCircle2,
|
||||
MessageSquare,
|
||||
Shield,
|
||||
User,
|
||||
VolumeX,
|
||||
Zap,
|
||||
} from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import {
|
||||
assignCfhTicket,
|
||||
closeCfhTicket,
|
||||
quickAlert,
|
||||
quickKick,
|
||||
quickMute,
|
||||
updateCfhState,
|
||||
} from "@/actions/moderation";
|
||||
import Link from "@/components/link";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { useServerAction } from "@/hooks/use-server-action";
|
||||
|
||||
const CFH_STATES: Record<number, { label: string; class: string }> = {
|
||||
0: {
|
||||
label: "Open",
|
||||
class: "bg-[var(--admin-error-subtle)] text-[var(--admin-error)]",
|
||||
},
|
||||
1: {
|
||||
label: "Picked",
|
||||
class: "bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]",
|
||||
},
|
||||
2: { label: "Closed", class: "bg-muted text-muted-foreground" },
|
||||
};
|
||||
|
||||
interface UserInfo {
|
||||
id: number;
|
||||
username: string;
|
||||
look: string;
|
||||
rank: number;
|
||||
online: string;
|
||||
ipRegister: string;
|
||||
mail: string | null;
|
||||
}
|
||||
|
||||
interface BanRecord {
|
||||
id: number;
|
||||
reason: string;
|
||||
type: string;
|
||||
staff: string;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
export function CfhDetail({
|
||||
ticket,
|
||||
sender,
|
||||
reported,
|
||||
moderator,
|
||||
banHistory,
|
||||
canEdit,
|
||||
currentUserId,
|
||||
listHref = "/admin/moderation/cfh",
|
||||
userLinkMode = "admin",
|
||||
}: {
|
||||
ticket: {
|
||||
id: number;
|
||||
state: number;
|
||||
type: number;
|
||||
timestamp: number;
|
||||
issue: string;
|
||||
roomId: number;
|
||||
category: number;
|
||||
score: number;
|
||||
};
|
||||
sender: UserInfo | null;
|
||||
reported: UserInfo | null;
|
||||
moderator: UserInfo | null;
|
||||
banHistory: { count: number; recent: BanRecord[] };
|
||||
canEdit: boolean;
|
||||
currentUserId: number;
|
||||
listHref?: string;
|
||||
userLinkMode?: "admin" | "public";
|
||||
}) {
|
||||
void currentUserId;
|
||||
const { run, isPending } = useServerAction();
|
||||
const [alertMsg, setAlertMsg] = useState("");
|
||||
const [muteDuration, setMuteDuration] = useState(10);
|
||||
|
||||
const state = CFH_STATES[ticket.state] ?? CFH_STATES[0];
|
||||
|
||||
function userHref(user: UserInfo) {
|
||||
if (userLinkMode === "public") {
|
||||
return `/u/${encodeURIComponent(user.username)}`;
|
||||
}
|
||||
return `/admin/users/show/${user.id}`;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-start gap-4">
|
||||
<Link href={listHref}>
|
||||
<Button variant="ghost" size="icon">
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<span className="text-sm text-muted-foreground font-mono">
|
||||
CFH #{ticket.id}
|
||||
</span>
|
||||
<Badge className={state.class}>{state.label}</Badge>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Type {ticket.type} · Category {ticket.category}
|
||||
</span>
|
||||
</div>
|
||||
<h1 className="text-xl font-bold">Call For Help Report</h1>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{new Date(ticket.timestamp * 1000).toLocaleString()} · Room #
|
||||
{ticket.roomId}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 lg:grid-cols-[1fr_300px]">
|
||||
{/* Main content */}
|
||||
<div className="space-y-4">
|
||||
{/* Issue */}
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm flex items-center gap-2">
|
||||
<MessageSquare className="h-4 w-4" />
|
||||
Report Message
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm leading-relaxed whitespace-pre-wrap">
|
||||
{ticket.issue || "No description provided."}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Users involved */}
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
{/* Sender */}
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm text-[var(--admin-info)]">
|
||||
Reporter
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{sender ? (
|
||||
<Link
|
||||
href={userHref(sender)}
|
||||
className="flex items-center gap-3 hover:text-primary no-underline"
|
||||
>
|
||||
<User className="h-4 w-4" />
|
||||
<div>
|
||||
<p className="text-sm font-bold">{sender.username}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Rank {sender.rank} ·{" "}
|
||||
{sender.online === "1" ? "Online" : "Offline"}
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">Unknown user</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Reported */}
|
||||
<Card className="border-[var(--admin-error-border)]">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm text-[var(--admin-error)]">
|
||||
Reported User
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{reported ? (
|
||||
<div>
|
||||
<Link
|
||||
href={userHref(reported)}
|
||||
className="flex items-center gap-3 hover:text-primary no-underline"
|
||||
>
|
||||
<AlertTriangle className="h-4 w-4 text-[var(--admin-error)]" />
|
||||
<div>
|
||||
<p className="text-sm font-bold">{reported.username}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Rank {reported.rank} ·{" "}
|
||||
{reported.online === "1" ? "Online" : "Offline"} ·{" "}
|
||||
{banHistory.count} bans
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
{/* Quick actions on reported user */}
|
||||
{canEdit && (
|
||||
<div className="mt-3 pt-3 border-t space-y-2">
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
className="flex-1"
|
||||
disabled={isPending}
|
||||
onClick={() =>
|
||||
run(() => quickKick({ userId: reported.id }), {
|
||||
successMessage: "User kicked",
|
||||
})
|
||||
}
|
||||
>
|
||||
<Zap className="mr-1 h-3 w-3" /> Kick
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="flex-1"
|
||||
disabled={isPending}
|
||||
onClick={() =>
|
||||
run(
|
||||
() =>
|
||||
quickMute({
|
||||
userId: reported.id,
|
||||
duration: muteDuration,
|
||||
}),
|
||||
{
|
||||
successMessage: `Muted for ${muteDuration}min`,
|
||||
},
|
||||
)
|
||||
}
|
||||
>
|
||||
<VolumeX className="mr-1 h-3 w-3" /> Mute
|
||||
</Button>
|
||||
</div>
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
max={1440}
|
||||
value={muteDuration}
|
||||
onChange={(e) =>
|
||||
setMuteDuration(Number(e.target.value))
|
||||
}
|
||||
className="h-7 text-xs"
|
||||
placeholder="Mute duration (min)"
|
||||
/>
|
||||
<div className="flex gap-2">
|
||||
<Textarea
|
||||
value={alertMsg}
|
||||
onChange={(e) => setAlertMsg(e.target.value)}
|
||||
placeholder="Alert message..."
|
||||
rows={2}
|
||||
className="text-xs resize-none"
|
||||
/>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="shrink-0"
|
||||
disabled={isPending || !alertMsg.trim()}
|
||||
onClick={() => {
|
||||
run(
|
||||
() =>
|
||||
quickAlert({
|
||||
userId: reported.id,
|
||||
message: alertMsg.trim(),
|
||||
}),
|
||||
{
|
||||
successMessage: "Alert sent",
|
||||
onSuccess: () => setAlertMsg(""),
|
||||
},
|
||||
);
|
||||
}}
|
||||
>
|
||||
Alert
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">Unknown user</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Ban history */}
|
||||
{banHistory.recent.length > 0 && (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm flex items-center gap-2">
|
||||
<Ban className="h-4 w-4 text-[var(--admin-error)]" />
|
||||
Ban History ({banHistory.count})
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="divide-y divide-border">
|
||||
{banHistory.recent.map((ban) => (
|
||||
<div
|
||||
key={ban.id}
|
||||
className="py-2 first:pt-0 last:pb-0 text-xs"
|
||||
>
|
||||
<p className="font-medium">{ban.reason || "No reason"}</p>
|
||||
<p className="text-muted-foreground">
|
||||
{ban.type} · by {ban.staff} ·{" "}
|
||||
{new Date(ban.timestamp * 1000).toLocaleDateString()}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Sidebar */}
|
||||
<div className="space-y-4">
|
||||
{/* Actions */}
|
||||
{canEdit && (
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">Actions</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<div>
|
||||
<span className="text-xs text-muted-foreground mb-1 block">
|
||||
Status
|
||||
</span>
|
||||
<Select
|
||||
value={String(ticket.state)}
|
||||
onValueChange={(v) =>
|
||||
run(
|
||||
() =>
|
||||
updateCfhState({
|
||||
ticketId: ticket.id,
|
||||
state: Number(v),
|
||||
}),
|
||||
{
|
||||
successMessage: "Status updated",
|
||||
},
|
||||
)
|
||||
}
|
||||
>
|
||||
<SelectTrigger className="h-8 text-xs">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="0" className="text-xs">
|
||||
Open
|
||||
</SelectItem>
|
||||
<SelectItem value="1" className="text-xs">
|
||||
Picked
|
||||
</SelectItem>
|
||||
<SelectItem value="2" className="text-xs">
|
||||
Closed
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="w-full"
|
||||
disabled={isPending}
|
||||
onClick={() =>
|
||||
run(() => assignCfhTicket({ ticketId: ticket.id }), {
|
||||
successMessage: "Assigned to you",
|
||||
})
|
||||
}
|
||||
>
|
||||
<Shield className="mr-1.5 h-3.5 w-3.5" /> Assign to me
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="w-full text-[var(--admin-success)]"
|
||||
disabled={isPending || ticket.state === 2}
|
||||
onClick={() =>
|
||||
run(() => closeCfhTicket({ ticketId: ticket.id }), {
|
||||
successMessage: "Ticket closed",
|
||||
})
|
||||
}
|
||||
>
|
||||
<CheckCircle2 className="mr-1.5 h-3.5 w-3.5" /> Close Ticket
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Moderator */}
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">Assigned Moderator</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{moderator ? (
|
||||
<Link
|
||||
href={userHref(moderator)}
|
||||
className="flex items-center gap-2 text-sm hover:text-primary no-underline"
|
||||
>
|
||||
<Shield className="h-3.5 w-3.5 text-primary" />
|
||||
{moderator.username}
|
||||
</Link>
|
||||
) : (
|
||||
<p className="text-xs text-muted-foreground">Unassigned</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Details */}
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm">Details</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-2 text-xs text-muted-foreground">
|
||||
<div className="flex justify-between">
|
||||
<span>Created</span>
|
||||
<span>
|
||||
{new Date(ticket.timestamp * 1000).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span>Room</span>
|
||||
<span>#{ticket.roomId}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span>Type</span>
|
||||
<span>{ticket.type}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span>Category</span>
|
||||
<span>{ticket.category}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span>Score</span>
|
||||
<span>{ticket.score}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import { count, desc, eq, inArray } from "drizzle-orm";
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
import { Ban, db, SupportTickets, User } from "@/lib/db";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { CfhDetail } from "./cfh-detail";
|
||||
|
||||
export default async function CfhDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>;
|
||||
}) {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.MODERATION_VIEW, session.user.rank))
|
||||
redirect("/admin");
|
||||
|
||||
const { id } = await params;
|
||||
const ticketId = Number(id);
|
||||
if (Number.isNaN(ticketId)) notFound();
|
||||
|
||||
const [ticket] = await db
|
||||
.select()
|
||||
.from(SupportTickets)
|
||||
.where(eq(SupportTickets.id, ticketId))
|
||||
.limit(1);
|
||||
if (!ticket) notFound();
|
||||
|
||||
const canEdit = canAccess(
|
||||
permissions,
|
||||
PERMS.MODERATION_EDIT,
|
||||
session.user.rank,
|
||||
);
|
||||
|
||||
// Fetch sender, reported, mod info
|
||||
const userIds = [ticket.senderId, ticket.reportedId, ticket.modId].filter(
|
||||
Boolean,
|
||||
) as number[];
|
||||
const users =
|
||||
userIds.length > 0
|
||||
? await db
|
||||
.select({
|
||||
id: User.id,
|
||||
username: User.username,
|
||||
look: User.look,
|
||||
rank: User.rank,
|
||||
online: User.online,
|
||||
ipRegister: User.ipRegister,
|
||||
mail: User.mail,
|
||||
})
|
||||
.from(User)
|
||||
.where(inArray(User.id, userIds))
|
||||
: [];
|
||||
const userMap = Object.fromEntries(users.map((u) => [u.id, u]));
|
||||
|
||||
// Get ban/mute history for reported user
|
||||
const reportedId = ticket.reportedId;
|
||||
const [banCountRows, recentBans] = reportedId
|
||||
? await Promise.all([
|
||||
db
|
||||
.select({ total: count() })
|
||||
.from(Ban)
|
||||
.where(eq(Ban.userId, reportedId)),
|
||||
db
|
||||
.select()
|
||||
.from(Ban)
|
||||
.where(eq(Ban.userId, reportedId))
|
||||
.orderBy(desc(Ban.id))
|
||||
.limit(5),
|
||||
])
|
||||
: [[{ total: 0 }], []];
|
||||
|
||||
const banCount = Number(banCountRows[0]?.total ?? 0);
|
||||
|
||||
return (
|
||||
<CfhDetail
|
||||
ticket={{
|
||||
id: ticket.id,
|
||||
state: ticket.state,
|
||||
type: ticket.type,
|
||||
timestamp: ticket.timestamp,
|
||||
issue: ticket.issue,
|
||||
roomId: ticket.roomId,
|
||||
category: ticket.category,
|
||||
score: ticket.score,
|
||||
}}
|
||||
sender={userMap[ticket.senderId] ?? null}
|
||||
reported={userMap[ticket.reportedId] ?? null}
|
||||
moderator={userMap[ticket.modId] ?? null}
|
||||
banHistory={{
|
||||
count: banCount,
|
||||
recent: recentBans.map((b) => ({
|
||||
id: b.id,
|
||||
reason: b.banReason,
|
||||
type: b.type,
|
||||
staff: `Staff #${b.userStaffId}`,
|
||||
timestamp: b.timestamp,
|
||||
})),
|
||||
}}
|
||||
canEdit={canEdit}
|
||||
currentUserId={session.user.id}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
"use client";
|
||||
|
||||
import { useTranslations } from "next-intl";
|
||||
import { DataTable } from "@/components/admin/data-table";
|
||||
import Link from "@/components/link";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import type { DataTableColumn, PaginatedResult } from "@/types/common";
|
||||
|
||||
export interface CfhRow {
|
||||
id: number;
|
||||
issue: string;
|
||||
roomId: number;
|
||||
when: string;
|
||||
sender: string;
|
||||
senderId: number;
|
||||
reported: string;
|
||||
reportedId: number;
|
||||
mod: string;
|
||||
state: number;
|
||||
stateLabel: string;
|
||||
}
|
||||
|
||||
export function CfhTable({
|
||||
data,
|
||||
basePath = "/admin/moderation/cfh",
|
||||
userLinkMode = "admin",
|
||||
}: {
|
||||
data: PaginatedResult<CfhRow>;
|
||||
/** Detail URL prefix (no trailing slash). */
|
||||
basePath?: string;
|
||||
/** Admin user show vs public profile. */
|
||||
userLinkMode?: "admin" | "public";
|
||||
}) {
|
||||
const t = useTranslations("pages.admin.cfh");
|
||||
|
||||
function userHref(id: number, username: string) {
|
||||
if (userLinkMode === "public" && username && username !== "—") {
|
||||
return `/u/${encodeURIComponent(username)}`;
|
||||
}
|
||||
return `/admin/users/${id}`;
|
||||
}
|
||||
|
||||
const columns: DataTableColumn<CfhRow>[] = [
|
||||
{ key: "id", label: t("colId"), sortable: true },
|
||||
{
|
||||
key: "issue",
|
||||
label: t("colIssue"),
|
||||
sortable: true,
|
||||
render: (_value, row) => (
|
||||
<div className="min-w-0">
|
||||
<Link
|
||||
href={`${basePath}/${row.id}`}
|
||||
className="text-sm font-medium truncate block hover:underline"
|
||||
>
|
||||
{row.issue || t("noDescription")}
|
||||
</Link>
|
||||
<p className="text-[10px] text-muted-foreground">
|
||||
{t("roomMeta", { room: row.roomId, when: row.when })}
|
||||
</p>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "sender",
|
||||
label: t("colSender"),
|
||||
sortable: true,
|
||||
render: (_value, row) =>
|
||||
row.senderId ? (
|
||||
<Link
|
||||
href={userHref(row.senderId, row.sender)}
|
||||
className="hover:underline"
|
||||
>
|
||||
{row.sender}
|
||||
</Link>
|
||||
) : (
|
||||
"—"
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "reported",
|
||||
label: t("colReported"),
|
||||
sortable: true,
|
||||
render: (_value, row) =>
|
||||
row.reportedId ? (
|
||||
<Link
|
||||
href={userHref(row.reportedId, row.reported)}
|
||||
className="font-medium hover:underline"
|
||||
>
|
||||
{row.reported}
|
||||
</Link>
|
||||
) : (
|
||||
"—"
|
||||
),
|
||||
},
|
||||
{ key: "mod", label: t("colMod"), sortable: true },
|
||||
{
|
||||
key: "state",
|
||||
label: t("colStatus"),
|
||||
sortable: true,
|
||||
filterKey: "filter_state",
|
||||
filterOptions: [
|
||||
{ label: t("stateOpen"), value: "0" },
|
||||
{ label: t("statePicked"), value: "1" },
|
||||
{ label: t("stateClosed"), value: "2" },
|
||||
],
|
||||
render: (_value, row) => {
|
||||
const variant =
|
||||
row.state === 0
|
||||
? "destructive"
|
||||
: row.state === 1
|
||||
? "default"
|
||||
: "secondary";
|
||||
return (
|
||||
<Badge variant={variant} className="text-[0.7rem]">
|
||||
{row.stateLabel}
|
||||
</Badge>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<DataTable
|
||||
data={data}
|
||||
columns={columns}
|
||||
searchPlaceholder={t("searchPlaceholder")}
|
||||
presets={[
|
||||
{ label: t("stateOpen"), params: { filter_state: "0" } },
|
||||
{ label: t("statePicked"), params: { filter_state: "1" } },
|
||||
{ label: t("stateClosed"), params: { filter_state: "2" } },
|
||||
]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import {
|
||||
and,
|
||||
asc,
|
||||
count,
|
||||
desc,
|
||||
eq,
|
||||
inArray,
|
||||
like,
|
||||
or,
|
||||
type SQL,
|
||||
} from "drizzle-orm";
|
||||
import { redirect } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { calcPagination, parseListParams } from "@/lib/admin-helpers";
|
||||
import { db, SupportTickets, User } from "@/lib/db";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { type CfhRow, CfhTable } from "./cfh-table";
|
||||
|
||||
export default async function CfhListPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<Record<string, string>>;
|
||||
}) {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.MODERATION_VIEW, session.user.rank)) {
|
||||
redirect("/admin");
|
||||
}
|
||||
|
||||
const t = await getTranslations("pages.admin.cfh");
|
||||
const raw = await searchParams;
|
||||
const parsed = parseListParams(new URLSearchParams(raw));
|
||||
const stateRaw = raw.filter_state ?? raw.state;
|
||||
const stateFilter =
|
||||
stateRaw !== undefined && stateRaw !== "" ? Number(stateRaw) : -1;
|
||||
|
||||
const conditions: SQL[] = [];
|
||||
if (stateFilter >= 0) {
|
||||
conditions.push(eq(SupportTickets.state, stateFilter));
|
||||
}
|
||||
|
||||
if (parsed.search.trim()) {
|
||||
const q = parsed.search.trim();
|
||||
const asId = Number(q);
|
||||
let userIds: number[] = [];
|
||||
try {
|
||||
const users = await db
|
||||
.select({ id: User.id })
|
||||
.from(User)
|
||||
.where(like(User.username, `%${q}%`))
|
||||
.limit(50);
|
||||
userIds = users.map((u) => u.id);
|
||||
} catch {
|
||||
userIds = [];
|
||||
}
|
||||
|
||||
const searchFilter = or(
|
||||
like(SupportTickets.issue, `%${q}%`),
|
||||
...(Number.isFinite(asId) && asId > 0
|
||||
? [eq(SupportTickets.id, asId)]
|
||||
: []),
|
||||
...(userIds.length
|
||||
? [
|
||||
inArray(SupportTickets.senderId, userIds),
|
||||
inArray(SupportTickets.reportedId, userIds),
|
||||
inArray(SupportTickets.modId, userIds),
|
||||
]
|
||||
: []),
|
||||
);
|
||||
if (searchFilter) conditions.push(searchFilter);
|
||||
}
|
||||
|
||||
const where = conditions.length > 0 ? and(...conditions) : undefined;
|
||||
|
||||
const orderCol =
|
||||
parsed.sort === "issue"
|
||||
? SupportTickets.issue
|
||||
: parsed.sort === "sender"
|
||||
? SupportTickets.senderId
|
||||
: parsed.sort === "reported"
|
||||
? SupportTickets.reportedId
|
||||
: parsed.sort === "mod"
|
||||
? SupportTickets.modId
|
||||
: parsed.sort === "state"
|
||||
? SupportTickets.state
|
||||
: SupportTickets.id;
|
||||
const orderBy = parsed.order === "asc" ? asc(orderCol) : desc(orderCol);
|
||||
|
||||
const [totalRows] = await db
|
||||
.select({ total: count() })
|
||||
.from(SupportTickets)
|
||||
.where(where)
|
||||
.catch(() => [{ total: 0 }]);
|
||||
const total = Number(totalRows?.total ?? 0);
|
||||
const pagination = calcPagination(total, parsed.page, parsed.perPage);
|
||||
|
||||
const tickets = await db
|
||||
.select()
|
||||
.from(SupportTickets)
|
||||
.where(where)
|
||||
.orderBy(orderBy)
|
||||
.limit(pagination.perPage)
|
||||
.offset(pagination.offset)
|
||||
.catch(() => []);
|
||||
|
||||
const userIds = [
|
||||
...new Set([
|
||||
...tickets.map((x) => x.senderId),
|
||||
...tickets.map((x) => x.reportedId),
|
||||
...tickets.map((x) => x.modId),
|
||||
]),
|
||||
].filter(Boolean) as number[];
|
||||
|
||||
let userMap = new Map<number, string>();
|
||||
if (userIds.length > 0) {
|
||||
try {
|
||||
const users = await db
|
||||
.select({ id: User.id, username: User.username })
|
||||
.from(User)
|
||||
.where(inArray(User.id, userIds));
|
||||
userMap = new Map(users.map((u) => [u.id, u.username]));
|
||||
} catch {
|
||||
userMap = new Map();
|
||||
}
|
||||
}
|
||||
|
||||
const stateLabels: Record<number, string> = {
|
||||
0: t("stateOpen"),
|
||||
1: t("statePicked"),
|
||||
2: t("stateClosed"),
|
||||
};
|
||||
|
||||
const rows: CfhRow[] = tickets.map((ticket) => ({
|
||||
id: ticket.id,
|
||||
issue: ticket.issue,
|
||||
roomId: ticket.roomId,
|
||||
when: ticket.timestamp
|
||||
? formatDate(new Date(ticket.timestamp * 1000))
|
||||
: "—",
|
||||
sender: userMap.get(ticket.senderId) ?? "—",
|
||||
senderId: ticket.senderId,
|
||||
reported: userMap.get(ticket.reportedId) ?? "—",
|
||||
reportedId: ticket.reportedId,
|
||||
mod: userMap.get(ticket.modId) ?? "—",
|
||||
state: ticket.state,
|
||||
stateLabel: stateLabels[ticket.state] ?? String(ticket.state),
|
||||
}));
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{total === 0 && !parsed.search && stateFilter < 0 ? (
|
||||
<div className="admin-empty">{t("noTickets")}</div>
|
||||
) : (
|
||||
<CfhTable
|
||||
data={{
|
||||
rows,
|
||||
total,
|
||||
page: pagination.page,
|
||||
perPage: pagination.perPage,
|
||||
lastPage: pagination.lastPage,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
import { and, count, desc, eq, gte, inArray, like } from "drizzle-orm";
|
||||
import {
|
||||
AlertTriangle,
|
||||
Ban as BanIcon,
|
||||
Clock,
|
||||
Gavel,
|
||||
Radio,
|
||||
Shield,
|
||||
User as UserIcon,
|
||||
} from "lucide-react";
|
||||
import { redirect } from "next/navigation";
|
||||
import { StatsCard } from "@/components/admin/stats-card";
|
||||
import Link from "@/components/link";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { getMinStaffRank } from "@/lib/admin/min-staff-rank";
|
||||
import { AdminAuditLog, Ban, db, SupportTickets, User } from "@/lib/db";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
|
||||
const CFH_STATES: Record<number, { label: string; class: string }> = {
|
||||
0: {
|
||||
label: "Open",
|
||||
class: "bg-[var(--admin-error-subtle)] text-[var(--admin-error)]",
|
||||
},
|
||||
1: {
|
||||
label: "Picked",
|
||||
class: "bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]",
|
||||
},
|
||||
2: { label: "Closed", class: "bg-muted text-muted-foreground" },
|
||||
};
|
||||
|
||||
export default async function ModerationDashboard() {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.MODERATION_VIEW, session.user.rank))
|
||||
redirect("/admin");
|
||||
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
const todayStart = now - (now % 86400);
|
||||
const minStaffRank = await getMinStaffRank();
|
||||
|
||||
const [
|
||||
openCfhRows,
|
||||
pickedCfhRows,
|
||||
todayBansRows,
|
||||
modsOnlineRows,
|
||||
recentCfh,
|
||||
recentModActions,
|
||||
] = await Promise.all([
|
||||
db
|
||||
.select({ total: count() })
|
||||
.from(SupportTickets)
|
||||
.where(eq(SupportTickets.state, 0)),
|
||||
db
|
||||
.select({ total: count() })
|
||||
.from(SupportTickets)
|
||||
.where(eq(SupportTickets.state, 1)),
|
||||
db
|
||||
.select({ total: count() })
|
||||
.from(Ban)
|
||||
.where(gte(Ban.timestamp, todayStart)),
|
||||
db
|
||||
.select({ total: count() })
|
||||
.from(User)
|
||||
.where(and(eq(User.online, "1"), gte(User.rank, minStaffRank))),
|
||||
db.select().from(SupportTickets).orderBy(desc(SupportTickets.id)).limit(10),
|
||||
db
|
||||
.select({
|
||||
id: AdminAuditLog.id,
|
||||
action: AdminAuditLog.action,
|
||||
details: AdminAuditLog.details,
|
||||
createdAt: AdminAuditLog.createdAt,
|
||||
userId: AdminAuditLog.userId,
|
||||
target: AdminAuditLog.target,
|
||||
targetId: AdminAuditLog.targetId,
|
||||
username: User.username,
|
||||
})
|
||||
.from(AdminAuditLog)
|
||||
.leftJoin(User, eq(AdminAuditLog.userId, User.id))
|
||||
.where(like(AdminAuditLog.action, "mod_%"))
|
||||
.orderBy(desc(AdminAuditLog.id))
|
||||
.limit(10),
|
||||
]);
|
||||
|
||||
const openCfh = Number(openCfhRows[0]?.total ?? 0);
|
||||
const pickedCfh = Number(pickedCfhRows[0]?.total ?? 0);
|
||||
const todayBans = Number(todayBansRows[0]?.total ?? 0);
|
||||
const modsOnline = Number(modsOnlineRows[0]?.total ?? 0);
|
||||
|
||||
// Fetch usernames for CFH tickets
|
||||
const userIds = [
|
||||
...new Set([
|
||||
...recentCfh.map((t) => t.senderId),
|
||||
...recentCfh.map((t) => t.reportedId),
|
||||
...recentCfh.map((t) => t.modId),
|
||||
]),
|
||||
].filter(Boolean) as number[];
|
||||
|
||||
const users =
|
||||
userIds.length > 0
|
||||
? await db
|
||||
.select({ id: User.id, username: User.username })
|
||||
.from(User)
|
||||
.where(inArray(User.id, userIds))
|
||||
: [];
|
||||
const userMap = new Map(users.map((u) => [u.id, u.username]));
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Stats */}
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||
<StatsCard
|
||||
title="Open CFH"
|
||||
value={openCfh}
|
||||
description={`${pickedCfh} picked`}
|
||||
icon={<Radio className="h-4 w-4" />}
|
||||
href="/admin/moderation/cfh"
|
||||
/>
|
||||
<StatsCard
|
||||
title="Bans Today"
|
||||
value={todayBans}
|
||||
icon={<BanIcon className="h-4 w-4" />}
|
||||
href="/admin/bans"
|
||||
/>
|
||||
<StatsCard
|
||||
title="Mods Online"
|
||||
value={modsOnline}
|
||||
icon={<Shield className="h-4 w-4" />}
|
||||
href="/admin/moderation/team"
|
||||
/>
|
||||
<StatsCard
|
||||
title="Quick Actions"
|
||||
value="→"
|
||||
description="Kick, mute, alert"
|
||||
icon={<Gavel className="h-4 w-4" />}
|
||||
href="/admin/moderation/actions"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 lg:grid-cols-2">
|
||||
{/* Recent CFH */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center justify-between">
|
||||
<span className="flex items-center gap-2">
|
||||
<AlertTriangle className="h-4 w-4 text-[var(--admin-error)]" />
|
||||
Recent CFH Tickets
|
||||
</span>
|
||||
<Link
|
||||
href="/admin/moderation/cfh"
|
||||
className="text-xs font-normal text-primary hover:underline"
|
||||
>
|
||||
View all
|
||||
</Link>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{recentCfh.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground text-center py-4">
|
||||
No CFH tickets
|
||||
</p>
|
||||
) : (
|
||||
<div className="divide-y divide-border">
|
||||
{recentCfh.map((ticket) => {
|
||||
const state = CFH_STATES[ticket.state] ?? CFH_STATES[0];
|
||||
return (
|
||||
<Link
|
||||
key={ticket.id}
|
||||
href={`/admin/moderation/cfh/${ticket.id}`}
|
||||
className="flex items-center gap-3 py-2.5 first:pt-0 last:pb-0 hover:bg-accent/50 -mx-2 px-2 rounded transition-colors"
|
||||
>
|
||||
<span className="text-xs font-mono text-muted-foreground w-8">
|
||||
#{ticket.id}
|
||||
</span>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm truncate">
|
||||
{ticket.issue || "No description"}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{userMap.get(ticket.senderId) ?? "?"} →{" "}
|
||||
{userMap.get(ticket.reportedId) ?? "?"}
|
||||
</p>
|
||||
</div>
|
||||
<Badge className={`text-[10px] ${state.class}`}>
|
||||
{state.label}
|
||||
</Badge>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Recent Mod Actions */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<Clock className="h-4 w-4" />
|
||||
Recent Mod Actions
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{recentModActions.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground text-center py-4">
|
||||
No recent actions
|
||||
</p>
|
||||
) : (
|
||||
<div className="divide-y divide-border">
|
||||
{recentModActions.map((log) => (
|
||||
<div
|
||||
key={log.id}
|
||||
className="flex items-center gap-3 py-2.5 first:pt-0 last:pb-0"
|
||||
>
|
||||
<UserIcon className="h-3.5 w-3.5 text-muted-foreground shrink-0" />
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium truncate">
|
||||
{log.action.replace("mod_", "").replace(/_/g, " ")}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
by {log.username ?? "?"} · {log.target}{" "}
|
||||
{log.targetId ? `#${log.targetId}` : ""}
|
||||
</p>
|
||||
</div>
|
||||
<span className="text-[10px] text-muted-foreground whitespace-nowrap">
|
||||
{log.createdAt}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
import { and, count, desc, gte, inArray, like } from "drizzle-orm";
|
||||
import { redirect } from "next/navigation";
|
||||
import Link from "@/components/link";
|
||||
import { AvatarImage } from "@/components/shared/avatar-image";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { getMinStaffRank } from "@/lib/admin/min-staff-rank";
|
||||
import {
|
||||
AdminAuditLog,
|
||||
db,
|
||||
SupportTickets,
|
||||
User,
|
||||
WebsiteTicket,
|
||||
} from "@/lib/db";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
|
||||
export default async function ModTeamPage() {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.MODERATION_VIEW, session.user.rank))
|
||||
redirect("/admin");
|
||||
|
||||
const minStaffRank = await getMinStaffRank();
|
||||
const staff = await db
|
||||
.select({
|
||||
id: User.id,
|
||||
username: User.username,
|
||||
look: User.look,
|
||||
rank: User.rank,
|
||||
online: User.online,
|
||||
lastLogin: User.lastLogin,
|
||||
lastOnline: User.lastOnline,
|
||||
})
|
||||
.from(User)
|
||||
.where(gte(User.rank, minStaffRank))
|
||||
.orderBy(desc(User.online), desc(User.rank));
|
||||
|
||||
const staffIds = staff.map((s) => s.id);
|
||||
|
||||
// Get CFH ticket counts per mod and web ticket counts
|
||||
const [cfhCounts, webTicketCounts, modActionCounts] = await Promise.all([
|
||||
staffIds.length
|
||||
? db
|
||||
.select({
|
||||
modId: SupportTickets.modId,
|
||||
total: count(),
|
||||
})
|
||||
.from(SupportTickets)
|
||||
.where(inArray(SupportTickets.modId, staffIds))
|
||||
.groupBy(SupportTickets.modId)
|
||||
: Promise.resolve([]),
|
||||
staffIds.length
|
||||
? db
|
||||
.select({
|
||||
assigneeId: WebsiteTicket.assigneeId,
|
||||
total: count(),
|
||||
})
|
||||
.from(WebsiteTicket)
|
||||
.where(inArray(WebsiteTicket.assigneeId, staffIds))
|
||||
.groupBy(WebsiteTicket.assigneeId)
|
||||
: Promise.resolve([]),
|
||||
staffIds.length
|
||||
? db
|
||||
.select({
|
||||
userId: AdminAuditLog.userId,
|
||||
total: count(),
|
||||
})
|
||||
.from(AdminAuditLog)
|
||||
.where(
|
||||
and(
|
||||
inArray(AdminAuditLog.userId, staffIds),
|
||||
like(AdminAuditLog.action, "mod_%"),
|
||||
),
|
||||
)
|
||||
.groupBy(AdminAuditLog.userId)
|
||||
: Promise.resolve([]),
|
||||
]);
|
||||
|
||||
const cfhMap = new Map(cfhCounts.map((c) => [c.modId, Number(c.total)]));
|
||||
const webMap = new Map(
|
||||
webTicketCounts.map((c) => [c.assigneeId, Number(c.total)]),
|
||||
);
|
||||
const actionMap = new Map(
|
||||
modActionCounts.map((c) => [c.userId, Number(c.total)]),
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Summary */}
|
||||
<div className="grid gap-4 grid-cols-3">
|
||||
<Card>
|
||||
<CardContent className="pt-4 text-center">
|
||||
<p className="text-2xl font-bold text-[var(--admin-success)]">
|
||||
{staff.filter((s) => s.online === "1").length}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">Online Now</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardContent className="pt-4 text-center">
|
||||
<p className="text-2xl font-bold">{staff.length}</p>
|
||||
<p className="text-xs text-muted-foreground">Total Staff</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardContent className="pt-4 text-center">
|
||||
<p className="text-2xl font-bold text-primary">
|
||||
{staff.filter((s) => s.rank > minStaffRank).length}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">Above min rank</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Staff list */}
|
||||
<div className="rounded-lg border">
|
||||
<div className="grid grid-cols-[auto_1fr_auto_auto_auto_auto_auto] gap-4 p-3 bg-muted/50 text-xs font-medium text-muted-foreground border-b">
|
||||
<span></span>
|
||||
<span>Name</span>
|
||||
<span>Rank</span>
|
||||
<span>CFH</span>
|
||||
<span>Tickets</span>
|
||||
<span>Actions</span>
|
||||
<span>Last Seen</span>
|
||||
</div>
|
||||
|
||||
{staff.map((member) => (
|
||||
<Link
|
||||
key={member.id}
|
||||
href={`/admin/users/show/${member.id}`}
|
||||
className="grid grid-cols-[auto_1fr_auto_auto_auto_auto_auto] gap-4 p-3 items-center hover:bg-accent/50 transition-all duration-150 border-b last:border-0"
|
||||
>
|
||||
<div className="relative">
|
||||
<AvatarImage
|
||||
figure={member.look}
|
||||
options={{ headOnly: true }}
|
||||
alt={member.username}
|
||||
width={32}
|
||||
height={32}
|
||||
/>
|
||||
<span
|
||||
className={`absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 rounded-full border-2 border-background ${
|
||||
member.online === "1"
|
||||
? "bg-[var(--admin-success)]"
|
||||
: "bg-[var(--admin-text-muted)]"
|
||||
}`}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium">{member.username}</p>
|
||||
</div>
|
||||
<Badge variant="outline" className="text-[10px]">
|
||||
Rank {member.rank}
|
||||
</Badge>
|
||||
<div className="text-center">
|
||||
<p className="text-sm font-bold">{cfhMap.get(member.id) ?? 0}</p>
|
||||
<p className="text-[9px] text-muted-foreground">CFH</p>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<p className="text-sm font-bold">{webMap.get(member.id) ?? 0}</p>
|
||||
<p className="text-[9px] text-muted-foreground">Web</p>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<p className="text-sm font-bold">
|
||||
{actionMap.get(member.id) ?? 0}
|
||||
</p>
|
||||
<p className="text-[9px] text-muted-foreground">Mod</p>
|
||||
</div>
|
||||
<span className="text-xs text-muted-foreground whitespace-nowrap">
|
||||
{member.online === "1"
|
||||
? "Online"
|
||||
: member.lastOnline
|
||||
? new Date(member.lastOnline * 1000).toLocaleDateString()
|
||||
: "—"}
|
||||
</span>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user