revert fb8e77bb68
Local Build and Deploy / deploy (push) Successful in 1m11s
Local Build and Deploy / deploy (push) Successful in 1m11s
revert style: clean up code with prettier and eslint
This commit is contained in:
1 parent
27de078f54
commit
e85e4d74ea
378 files changed
+20710
-22428
No files matched your search
@@ -1,7 +1,16 @@
|
||||
"use client";
|
||||
'use client'
|
||||
|
||||
import { DoorOpen, Loader2, Megaphone, MessageSquare, Shield, Volume2, VolumeX, Zap } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import {
|
||||
DoorOpen,
|
||||
Loader2,
|
||||
Megaphone,
|
||||
MessageSquare,
|
||||
Shield,
|
||||
Volume2,
|
||||
VolumeX,
|
||||
Zap,
|
||||
} from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import {
|
||||
broadcastAlert,
|
||||
quickAlert,
|
||||
@@ -9,29 +18,29 @@ import {
|
||||
quickMute,
|
||||
quickRoomKick,
|
||||
quickUnmute,
|
||||
} from "@/actions/moderation";
|
||||
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";
|
||||
} from '@/actions/moderation'
|
||||
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 { run, isPending } = useServerAction()
|
||||
|
||||
// User actions
|
||||
const [userId, setUserId] = useState("");
|
||||
const [muteDuration, setMuteDuration] = useState("10");
|
||||
const [alertMessage, setAlertMessage] = useState("");
|
||||
const [userId, setUserId] = useState('')
|
||||
const [muteDuration, setMuteDuration] = useState('10')
|
||||
const [alertMessage, setAlertMessage] = useState('')
|
||||
|
||||
// Room actions
|
||||
const [roomId, setRoomId] = useState("");
|
||||
const [roomId, setRoomId] = useState('')
|
||||
|
||||
// Broadcast
|
||||
const [broadcastMsg, setBroadcastMsg] = useState("");
|
||||
const [broadcastMsg, setBroadcastMsg] = useState('')
|
||||
|
||||
const uid = parseInt(userId, 10);
|
||||
const rid = parseInt(roomId, 10);
|
||||
const uid = parseInt(userId, 10)
|
||||
const rid = parseInt(roomId, 10)
|
||||
|
||||
return (
|
||||
<div className="grid gap-6 lg:grid-cols-2">
|
||||
@@ -59,7 +68,9 @@ export function ModActionsClient() {
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
disabled={isPending || !uid}
|
||||
onClick={() => run(() => quickKick({ userId: uid }), { successMessage: "User disconnected" })}
|
||||
onClick={() =>
|
||||
run(() => quickKick({ userId: uid }), { successMessage: 'User disconnected' })
|
||||
}
|
||||
>
|
||||
{isPending ? (
|
||||
<Loader2 className="mr-1 h-3 w-3 animate-spin" />
|
||||
@@ -72,7 +83,9 @@ export function ModActionsClient() {
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={isPending || !uid}
|
||||
onClick={() => run(() => quickUnmute({ userId: uid }), { successMessage: "User unmuted" })}
|
||||
onClick={() =>
|
||||
run(() => quickUnmute({ userId: uid }), { successMessage: 'User unmuted' })
|
||||
}
|
||||
>
|
||||
<Volume2 className="mr-1 h-3 w-3" /> Unmute
|
||||
</Button>
|
||||
@@ -118,9 +131,9 @@ export function ModActionsClient() {
|
||||
disabled={isPending || !uid || !alertMessage.trim()}
|
||||
onClick={() => {
|
||||
run(() => quickAlert({ userId: uid, message: alertMessage.trim() }), {
|
||||
successMessage: "Alert sent",
|
||||
onSuccess: () => setAlertMessage(""),
|
||||
});
|
||||
successMessage: 'Alert sent',
|
||||
onSuccess: () => setAlertMessage(''),
|
||||
})
|
||||
}}
|
||||
>
|
||||
<MessageSquare className="h-4 w-4" />
|
||||
@@ -155,7 +168,7 @@ export function ModActionsClient() {
|
||||
disabled={isPending || !rid}
|
||||
onClick={() =>
|
||||
run(() => quickRoomKick({ roomId: rid }), {
|
||||
successMessage: "All users kicked from room",
|
||||
successMessage: 'All users kicked from room',
|
||||
})
|
||||
}
|
||||
>
|
||||
@@ -185,10 +198,10 @@ export function ModActionsClient() {
|
||||
size="sm"
|
||||
disabled={isPending || !broadcastMsg.trim()}
|
||||
onClick={() => {
|
||||
run(() => broadcastAlert({ message: broadcastMsg.trim(), type: "hotel" }), {
|
||||
successMessage: "Hotel alert sent!",
|
||||
onSuccess: () => setBroadcastMsg(""),
|
||||
});
|
||||
run(() => broadcastAlert({ message: broadcastMsg.trim(), type: 'hotel' }), {
|
||||
successMessage: 'Hotel alert sent!',
|
||||
onSuccess: () => setBroadcastMsg(''),
|
||||
})
|
||||
}}
|
||||
>
|
||||
<Megaphone className="mr-1 h-3 w-3" /> Hotel Alert
|
||||
@@ -198,10 +211,10 @@ export function ModActionsClient() {
|
||||
size="sm"
|
||||
disabled={isPending || !broadcastMsg.trim()}
|
||||
onClick={() => {
|
||||
run(() => broadcastAlert({ message: broadcastMsg.trim(), type: "staff" }), {
|
||||
successMessage: "Staff alert sent!",
|
||||
onSuccess: () => setBroadcastMsg(""),
|
||||
});
|
||||
run(() => broadcastAlert({ message: broadcastMsg.trim(), type: 'staff' }), {
|
||||
successMessage: 'Staff alert sent!',
|
||||
onSuccess: () => setBroadcastMsg(''),
|
||||
})
|
||||
}}
|
||||
>
|
||||
<Shield className="mr-1 h-3 w-3" /> Staff Alert
|
||||
@@ -211,5 +224,5 @@ export function ModActionsClient() {
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
@@ -1,18 +1,20 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { ModActionsClient } from "./mod-actions-client";
|
||||
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");
|
||||
const { session, permissions } = await getAdminContext()
|
||||
if (!canAccess(permissions, PERMS.MODERATION_EDIT, session.user.rank)) redirect('/admin')
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Quick Actions</h1>
|
||||
<p className="text-muted-foreground">Fast moderation tools — kick, mute, alert, broadcast</p>
|
||||
<p className="text-muted-foreground">
|
||||
Fast moderation tools — kick, mute, alert, broadcast
|
||||
</p>
|
||||
</div>
|
||||
<ModActionsClient />
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
"use client";
|
||||
'use client'
|
||||
|
||||
import {
|
||||
AlertTriangle,
|
||||
@@ -10,9 +10,9 @@ import {
|
||||
User,
|
||||
VolumeX,
|
||||
Zap,
|
||||
} from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
} from 'lucide-react'
|
||||
import Link from 'next/link'
|
||||
import { useState } from 'react'
|
||||
import {
|
||||
assignCfhTicket,
|
||||
closeCfhTicket,
|
||||
@@ -20,37 +20,43 @@ import {
|
||||
quickKick,
|
||||
quickMute,
|
||||
updateCfhState,
|
||||
} from "@/actions/moderation";
|
||||
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";
|
||||
} from '@/actions/moderation'
|
||||
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" },
|
||||
};
|
||||
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;
|
||||
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;
|
||||
id: number
|
||||
reason: string
|
||||
type: string
|
||||
staff: string
|
||||
timestamp: number
|
||||
}
|
||||
|
||||
export function CfhDetail({
|
||||
@@ -64,27 +70,27 @@ export function CfhDetail({
|
||||
currentUserId,
|
||||
}: {
|
||||
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;
|
||||
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
|
||||
}) {
|
||||
const { run, isPending } = useServerAction();
|
||||
const [alertMsg, setAlertMsg] = useState("");
|
||||
const [muteDuration, setMuteDuration] = useState(10);
|
||||
const { run, isPending } = useServerAction()
|
||||
const [alertMsg, setAlertMsg] = useState('')
|
||||
const [muteDuration, setMuteDuration] = useState(10)
|
||||
|
||||
const state = CFH_STATES[ticket.state] ?? CFH_STATES[0];
|
||||
const state = CFH_STATES[ticket.state] ?? CFH_STATES[0]
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -123,7 +129,7 @@ export function CfhDetail({
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm leading-relaxed whitespace-pre-wrap">
|
||||
{ticket.issue || "No description provided."}
|
||||
{ticket.issue || 'No description provided.'}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -145,7 +151,7 @@ export function CfhDetail({
|
||||
<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"}
|
||||
Rank {sender.rank} · {sender.online === '1' ? 'Online' : 'Offline'}
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
@@ -171,7 +177,7 @@ export function CfhDetail({
|
||||
<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"} ·{" "}
|
||||
Rank {reported.rank} · {reported.online === '1' ? 'Online' : 'Offline'} ·{' '}
|
||||
{banHistory.count} bans
|
||||
</p>
|
||||
</div>
|
||||
@@ -188,7 +194,7 @@ export function CfhDetail({
|
||||
disabled={isPending}
|
||||
onClick={() =>
|
||||
run(() => quickKick({ userId: reported.id }), {
|
||||
successMessage: "User kicked",
|
||||
successMessage: 'User kicked',
|
||||
})
|
||||
}
|
||||
>
|
||||
@@ -200,9 +206,10 @@ export function CfhDetail({
|
||||
className="flex-1"
|
||||
disabled={isPending}
|
||||
onClick={() =>
|
||||
run(() => quickMute({ userId: reported.id, duration: muteDuration }), {
|
||||
successMessage: `Muted for ${muteDuration}min`,
|
||||
})
|
||||
run(
|
||||
() => quickMute({ userId: reported.id, duration: muteDuration }),
|
||||
{ successMessage: `Muted for ${muteDuration}min` },
|
||||
)
|
||||
}
|
||||
>
|
||||
<VolumeX className="mr-1 h-3 w-3" /> Mute
|
||||
@@ -231,10 +238,13 @@ export function CfhDetail({
|
||||
className="shrink-0"
|
||||
disabled={isPending || !alertMsg.trim()}
|
||||
onClick={() => {
|
||||
run(() => quickAlert({ userId: reported.id, message: alertMsg.trim() }), {
|
||||
successMessage: "Alert sent",
|
||||
onSuccess: () => setAlertMsg(""),
|
||||
});
|
||||
run(
|
||||
() => quickAlert({ userId: reported.id, message: alertMsg.trim() }),
|
||||
{
|
||||
successMessage: 'Alert sent',
|
||||
onSuccess: () => setAlertMsg(''),
|
||||
},
|
||||
)
|
||||
}}
|
||||
>
|
||||
Alert
|
||||
@@ -263,9 +273,10 @@ export function CfhDetail({
|
||||
<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="font-medium">{ban.reason || 'No reason'}</p>
|
||||
<p className="text-muted-foreground">
|
||||
{ban.type} · by {ban.staff} · {new Date(ban.timestamp * 1000).toLocaleDateString()}
|
||||
{ban.type} · by {ban.staff} ·{' '}
|
||||
{new Date(ban.timestamp * 1000).toLocaleDateString()}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
@@ -290,7 +301,7 @@ export function CfhDetail({
|
||||
value={String(ticket.state)}
|
||||
onValueChange={(v) =>
|
||||
run(() => updateCfhState({ ticketId: ticket.id, state: Number(v) }), {
|
||||
successMessage: "Status updated",
|
||||
successMessage: 'Status updated',
|
||||
})
|
||||
}
|
||||
>
|
||||
@@ -318,7 +329,7 @@ export function CfhDetail({
|
||||
disabled={isPending}
|
||||
onClick={() =>
|
||||
run(() => assignCfhTicket({ ticketId: ticket.id }), {
|
||||
successMessage: "Assigned to you",
|
||||
successMessage: 'Assigned to you',
|
||||
})
|
||||
}
|
||||
>
|
||||
@@ -332,7 +343,7 @@ export function CfhDetail({
|
||||
disabled={isPending || ticket.state === 2}
|
||||
onClick={() =>
|
||||
run(() => closeCfhTicket({ ticketId: ticket.id }), {
|
||||
successMessage: "Ticket closed",
|
||||
successMessage: 'Ticket closed',
|
||||
})
|
||||
}
|
||||
>
|
||||
@@ -393,5 +404,5 @@ export function CfhDetail({
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
@@ -1,23 +1,23 @@
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { CfhDetail } from "./cfh-detail";
|
||||
import { notFound, redirect } from 'next/navigation'
|
||||
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
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 { 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 { id } = await params
|
||||
const ticketId = Number(id)
|
||||
if (Number.isNaN(ticketId)) notFound()
|
||||
|
||||
const ticket = await prisma.supportTickets.findUnique({ where: { id: ticketId } });
|
||||
if (!ticket) notFound();
|
||||
const ticket = await prisma.supportTickets.findUnique({ where: { id: ticketId } })
|
||||
if (!ticket) notFound()
|
||||
|
||||
const canEdit = canAccess(permissions, PERMS.MODERATION_EDIT, session.user.rank);
|
||||
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);
|
||||
const userIds = [ticket.senderId, ticket.reportedId, ticket.modId].filter(Boolean)
|
||||
const users =
|
||||
userIds.length > 0
|
||||
? await prisma.user.findMany({
|
||||
@@ -32,21 +32,21 @@ export default async function CfhDetailPage({ params }: { params: Promise<{ id:
|
||||
mail: true,
|
||||
},
|
||||
})
|
||||
: [];
|
||||
const userMap = Object.fromEntries(users.map((u) => [u.id, u]));
|
||||
: []
|
||||
const userMap = Object.fromEntries(users.map((u) => [u.id, u]))
|
||||
|
||||
// Get ban/mute history for reported user
|
||||
const reportedId = ticket.reportedId;
|
||||
const reportedId = ticket.reportedId
|
||||
const [banCount, recentBans] = reportedId
|
||||
? await Promise.all([
|
||||
prisma.ban.count({ where: { userId: reportedId } }),
|
||||
prisma.ban.findMany({
|
||||
where: { userId: reportedId },
|
||||
orderBy: { id: "desc" },
|
||||
orderBy: { id: 'desc' },
|
||||
take: 5,
|
||||
}),
|
||||
])
|
||||
: [0, []];
|
||||
: [0, []]
|
||||
|
||||
return (
|
||||
<CfhDetail
|
||||
@@ -76,5 +76,5 @@ export default async function CfhDetailPage({ params }: { params: Promise<{ id:
|
||||
canEdit={canEdit}
|
||||
currentUserId={session.user.id}
|
||||
/>
|
||||
);
|
||||
)
|
||||
}
|
||||
@@ -1,44 +1,40 @@
|
||||
import { AlertTriangle, CheckCircle2, Clock, Radio } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { AlertTriangle, CheckCircle2, Clock, Radio } from 'lucide-react'
|
||||
import Link from 'next/link'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
|
||||
const CFH_STATES: Record<number, { label: string; class: string; icon: typeof AlertTriangle }> = {
|
||||
0: {
|
||||
label: "Open",
|
||||
class: "bg-[var(--admin-error-subtle)] text-[var(--admin-error)]",
|
||||
icon: AlertTriangle,
|
||||
},
|
||||
1: { label: "Picked", class: "bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]", icon: Clock },
|
||||
2: { label: "Closed", class: "bg-muted text-muted-foreground", icon: CheckCircle2 },
|
||||
};
|
||||
0: { label: 'Open', class: 'bg-[var(--admin-error-subtle)] text-[var(--admin-error)]', icon: AlertTriangle },
|
||||
1: { label: 'Picked', class: 'bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]', icon: Clock },
|
||||
2: { label: 'Closed', class: 'bg-muted text-muted-foreground', icon: CheckCircle2 },
|
||||
}
|
||||
|
||||
interface PageProps {
|
||||
searchParams: Promise<{ state?: string; page?: string }>;
|
||||
searchParams: Promise<{ state?: string; page?: string }>
|
||||
}
|
||||
|
||||
export default async function CfhListPage({ searchParams }: PageProps) {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.MODERATION_VIEW, session.user.rank)) redirect("/admin");
|
||||
const { session, permissions } = await getAdminContext()
|
||||
if (!canAccess(permissions, PERMS.MODERATION_VIEW, session.user.rank)) redirect('/admin')
|
||||
|
||||
const sp = await searchParams;
|
||||
const stateFilter = sp.state !== undefined ? Number(sp.state) : -1;
|
||||
const page = Math.max(1, Number(sp.page) || 1);
|
||||
const perPage = 25;
|
||||
const sp = await searchParams
|
||||
const stateFilter = sp.state !== undefined ? Number(sp.state) : -1
|
||||
const page = Math.max(1, Number(sp.page) || 1)
|
||||
const perPage = 25
|
||||
|
||||
const where = stateFilter >= 0 ? { state: stateFilter } : {};
|
||||
const where = stateFilter >= 0 ? { state: stateFilter } : {}
|
||||
|
||||
const [tickets, total] = await Promise.all([
|
||||
prisma.supportTickets.findMany({
|
||||
where,
|
||||
orderBy: { id: "desc" },
|
||||
orderBy: { id: 'desc' },
|
||||
skip: (page - 1) * perPage,
|
||||
take: perPage,
|
||||
}),
|
||||
prisma.supportTickets.count({ where }),
|
||||
]);
|
||||
])
|
||||
|
||||
// Fetch all related users
|
||||
const userIds = [
|
||||
@@ -47,7 +43,7 @@ export default async function CfhListPage({ searchParams }: PageProps) {
|
||||
...tickets.map((t) => t.reportedId),
|
||||
...tickets.map((t) => t.modId),
|
||||
]),
|
||||
].filter(Boolean);
|
||||
].filter(Boolean)
|
||||
|
||||
const users =
|
||||
userIds.length > 0
|
||||
@@ -55,10 +51,10 @@ export default async function CfhListPage({ searchParams }: PageProps) {
|
||||
where: { id: { in: userIds } },
|
||||
select: { id: true, username: true },
|
||||
})
|
||||
: [];
|
||||
const userMap = new Map(users.map((u) => [u.id, u.username]));
|
||||
: []
|
||||
const userMap = new Map(users.map((u) => [u.id, u.username]))
|
||||
|
||||
const totalPages = Math.ceil(total / perPage);
|
||||
const totalPages = Math.ceil(total / perPage)
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -70,13 +66,13 @@ export default async function CfhListPage({ searchParams }: PageProps) {
|
||||
{/* Filters */}
|
||||
<div className="flex gap-2">
|
||||
{[
|
||||
{ key: -1, label: "All" },
|
||||
{ key: 0, label: "Open" },
|
||||
{ key: 1, label: "Picked" },
|
||||
{ key: 2, label: "Closed" },
|
||||
{ key: -1, label: 'All' },
|
||||
{ key: 0, label: 'Open' },
|
||||
{ key: 1, label: 'Picked' },
|
||||
{ key: 2, label: 'Closed' },
|
||||
].map(({ key, label }) => (
|
||||
<Link key={key} href={`/admin/moderation/cfh${key >= 0 ? `?state=${key}` : ""}`}>
|
||||
<Badge variant={stateFilter === key ? "default" : "outline"} className="cursor-pointer">
|
||||
<Link key={key} href={`/admin/moderation/cfh${key >= 0 ? `?state=${key}` : ''}`}>
|
||||
<Badge variant={stateFilter === key ? 'default' : 'outline'} className="cursor-pointer">
|
||||
{label}
|
||||
</Badge>
|
||||
</Link>
|
||||
@@ -101,8 +97,8 @@ export default async function CfhListPage({ searchParams }: PageProps) {
|
||||
</div>
|
||||
) : (
|
||||
tickets.map((ticket) => {
|
||||
const state = CFH_STATES[ticket.state] ?? CFH_STATES[0];
|
||||
const StateIcon = state.icon;
|
||||
const state = CFH_STATES[ticket.state] ?? CFH_STATES[0]
|
||||
const StateIcon = state.icon
|
||||
|
||||
return (
|
||||
<Link
|
||||
@@ -112,17 +108,19 @@ export default async function CfhListPage({ searchParams }: PageProps) {
|
||||
>
|
||||
<span className="text-xs font-mono text-muted-foreground">{ticket.id}</span>
|
||||
<div className="min-w-0">
|
||||
<p className="text-sm truncate">{ticket.issue || "No description"}</p>
|
||||
<p className="text-sm truncate">{ticket.issue || 'No description'}</p>
|
||||
<p className="text-[10px] text-muted-foreground">
|
||||
Room #{ticket.roomId} · {new Date(ticket.timestamp * 1000).toLocaleString()}
|
||||
</p>
|
||||
</div>
|
||||
<span className="text-xs whitespace-nowrap">{userMap.get(ticket.senderId) ?? "—"}</span>
|
||||
<span className="text-xs whitespace-nowrap">
|
||||
{userMap.get(ticket.senderId) ?? '—'}
|
||||
</span>
|
||||
<span className="text-xs whitespace-nowrap font-medium">
|
||||
{userMap.get(ticket.reportedId) ?? "—"}
|
||||
{userMap.get(ticket.reportedId) ?? '—'}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground whitespace-nowrap">
|
||||
{userMap.get(ticket.modId) ?? "—"}
|
||||
{userMap.get(ticket.modId) ?? '—'}
|
||||
</span>
|
||||
<span
|
||||
className={`inline-flex items-center gap-1 text-xs font-medium px-2 py-0.5 rounded-full whitespace-nowrap ${state.class}`}
|
||||
@@ -131,7 +129,7 @@ export default async function CfhListPage({ searchParams }: PageProps) {
|
||||
{state.label}
|
||||
</span>
|
||||
</Link>
|
||||
);
|
||||
)
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
@@ -159,5 +157,5 @@ export default async function CfhListPage({ searchParams }: PageProps) {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
@@ -1,43 +1,44 @@
|
||||
import { AlertTriangle, Ban, Clock, Gavel, Radio, Shield, User } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import { StatsCard } from "@/components/admin/stats-card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { AlertTriangle, Ban, Clock, Gavel, Radio, Shield, User } from 'lucide-react'
|
||||
import Link from 'next/link'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { StatsCard } from '@/components/admin/stats-card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
|
||||
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" },
|
||||
};
|
||||
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 { 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 now = Math.floor(Date.now() / 1000)
|
||||
const todayStart = now - (now % 86400)
|
||||
|
||||
const [openCfh, pickedCfh, todayBans, modsOnline, recentCfh, recentModActions] = await Promise.all([
|
||||
prisma.supportTickets.count({ where: { state: 0 } }),
|
||||
prisma.supportTickets.count({ where: { state: 1 } }),
|
||||
prisma.ban.count({ where: { timestamp: { gte: todayStart } } }),
|
||||
prisma.user.count({ where: { online: "1", rank: { gte: 4 } } }),
|
||||
prisma.supportTickets.findMany({
|
||||
orderBy: { id: "desc" },
|
||||
take: 10,
|
||||
}),
|
||||
prisma.adminAuditLog.findMany({
|
||||
where: {
|
||||
action: { startsWith: "mod_" },
|
||||
},
|
||||
orderBy: { id: "desc" },
|
||||
take: 10,
|
||||
include: { user: { select: { username: true } } },
|
||||
}),
|
||||
]);
|
||||
const [openCfh, pickedCfh, todayBans, modsOnline, recentCfh, recentModActions] =
|
||||
await Promise.all([
|
||||
prisma.supportTickets.count({ where: { state: 0 } }),
|
||||
prisma.supportTickets.count({ where: { state: 1 } }),
|
||||
prisma.ban.count({ where: { timestamp: { gte: todayStart } } }),
|
||||
prisma.user.count({ where: { online: '1', rank: { gte: 4 } } }),
|
||||
prisma.supportTickets.findMany({
|
||||
orderBy: { id: 'desc' },
|
||||
take: 10,
|
||||
}),
|
||||
prisma.adminAuditLog.findMany({
|
||||
where: {
|
||||
action: { startsWith: 'mod_' },
|
||||
},
|
||||
orderBy: { id: 'desc' },
|
||||
take: 10,
|
||||
include: { user: { select: { username: true } } },
|
||||
}),
|
||||
])
|
||||
|
||||
// Fetch usernames for CFH tickets
|
||||
const userIds = [
|
||||
@@ -46,7 +47,7 @@ export default async function ModerationDashboard() {
|
||||
...recentCfh.map((t) => t.reportedId),
|
||||
...recentCfh.map((t) => t.modId),
|
||||
]),
|
||||
].filter(Boolean);
|
||||
].filter(Boolean)
|
||||
|
||||
const users =
|
||||
userIds.length > 0
|
||||
@@ -54,8 +55,8 @@ export default async function ModerationDashboard() {
|
||||
where: { id: { in: userIds } },
|
||||
select: { id: true, username: true },
|
||||
})
|
||||
: [];
|
||||
const userMap = new Map(users.map((u) => [u.id, u.username]));
|
||||
: []
|
||||
const userMap = new Map(users.map((u) => [u.id, u.username]))
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -103,7 +104,10 @@ export default async function ModerationDashboard() {
|
||||
<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">
|
||||
<Link
|
||||
href="/admin/moderation/cfh"
|
||||
className="text-xs font-normal text-primary hover:underline"
|
||||
>
|
||||
View all
|
||||
</Link>
|
||||
</CardTitle>
|
||||
@@ -114,23 +118,26 @@ export default async function ModerationDashboard() {
|
||||
) : (
|
||||
<div className="divide-y divide-border">
|
||||
{recentCfh.map((ticket) => {
|
||||
const state = CFH_STATES[ticket.state] ?? CFH_STATES[0];
|
||||
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>
|
||||
<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-sm truncate">{ticket.issue || 'No description'}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{userMap.get(ticket.senderId) ?? "?"} → {userMap.get(ticket.reportedId) ?? "?"}
|
||||
{userMap.get(ticket.senderId) ?? '?'} →{' '}
|
||||
{userMap.get(ticket.reportedId) ?? '?'}
|
||||
</p>
|
||||
</div>
|
||||
<Badge className={`text-[10px] ${state.class}`}>{state.label}</Badge>
|
||||
</Link>
|
||||
);
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
@@ -155,10 +162,11 @@ export default async function ModerationDashboard() {
|
||||
<User 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, " ")}
|
||||
{log.action.replace('mod_', '').replace(/_/g, ' ')}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
by {log.user?.username ?? "?"} · {log.target} {log.targetId ? `#${log.targetId}` : ""}
|
||||
by {log.user?.username ?? '?'} · {log.target}{' '}
|
||||
{log.targetId ? `#${log.targetId}` : ''}
|
||||
</p>
|
||||
</div>
|
||||
<span className="text-[10px] text-muted-foreground whitespace-nowrap">
|
||||
@@ -172,5 +180,5 @@ export default async function ModerationDashboard() {
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import { AvatarImage } from "@/components/shared/avatar-image";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import Link from 'next/link'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { AvatarImage } from '@/components/shared/avatar-image'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
|
||||
export default async function ModTeamPage() {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
if (!canAccess(permissions, PERMS.MODERATION_VIEW, session.user.rank)) redirect("/admin");
|
||||
const { session, permissions } = await getAdminContext()
|
||||
if (!canAccess(permissions, PERMS.MODERATION_VIEW, session.user.rank)) redirect('/admin')
|
||||
|
||||
// Get all staff (rank >= 4)
|
||||
const staff = await prisma.user.findMany({
|
||||
@@ -22,34 +22,34 @@ export default async function ModTeamPage() {
|
||||
lastLogin: true,
|
||||
lastOnline: true,
|
||||
},
|
||||
orderBy: [{ online: "desc" }, { rank: "desc" }],
|
||||
});
|
||||
orderBy: [{ online: 'desc' }, { rank: 'desc' }],
|
||||
})
|
||||
|
||||
// Get CFH ticket counts per mod and web ticket counts
|
||||
const [cfhCounts, webTicketCounts, modActionCounts] = await Promise.all([
|
||||
prisma.supportTickets.groupBy({
|
||||
by: ["modId"],
|
||||
by: ['modId'],
|
||||
where: { modId: { in: staff.map((s) => s.id) } },
|
||||
_count: { _all: true },
|
||||
}),
|
||||
prisma.websiteTicket.groupBy({
|
||||
by: ["assigneeId"],
|
||||
by: ['assigneeId'],
|
||||
where: { assigneeId: { in: staff.map((s) => s.id) } },
|
||||
_count: { _all: true },
|
||||
}),
|
||||
prisma.adminAuditLog.groupBy({
|
||||
by: ["userId"],
|
||||
by: ['userId'],
|
||||
where: {
|
||||
userId: { in: staff.map((s) => s.id) },
|
||||
action: { startsWith: "mod_" },
|
||||
action: { startsWith: 'mod_' },
|
||||
},
|
||||
_count: { _all: true },
|
||||
}),
|
||||
]);
|
||||
])
|
||||
|
||||
const cfhMap = new Map(cfhCounts.map((c) => [c.modId, c._count._all]));
|
||||
const webMap = new Map(webTicketCounts.map((c) => [c.assigneeId, c._count._all]));
|
||||
const actionMap = new Map(modActionCounts.map((c) => [c.userId, c._count._all]));
|
||||
const cfhMap = new Map(cfhCounts.map((c) => [c.modId, c._count._all]))
|
||||
const webMap = new Map(webTicketCounts.map((c) => [c.assigneeId, c._count._all]))
|
||||
const actionMap = new Map(modActionCounts.map((c) => [c.userId, c._count._all]))
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
@@ -63,7 +63,7 @@ export default async function ModTeamPage() {
|
||||
<Card>
|
||||
<CardContent className="pt-4 text-center">
|
||||
<p className="text-2xl font-bold text-[var(--admin-success)]">
|
||||
{staff.filter((s) => s.online === "1").length}
|
||||
{staff.filter((s) => s.online === '1').length}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">Online Now</p>
|
||||
</CardContent>
|
||||
@@ -76,7 +76,9 @@ export default async function ModTeamPage() {
|
||||
</Card>
|
||||
<Card>
|
||||
<CardContent className="pt-4 text-center">
|
||||
<p className="text-2xl font-bold text-primary">{staff.filter((s) => s.rank >= 7).length}</p>
|
||||
<p className="text-2xl font-bold text-primary">
|
||||
{staff.filter((s) => s.rank >= 7).length}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">Super Admins</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -103,14 +105,14 @@ export default async function ModTeamPage() {
|
||||
<div className="relative">
|
||||
<AvatarImage
|
||||
figure={member.look}
|
||||
options={{ headOnly: true, size: "l" }}
|
||||
options={{ headOnly: true, size: 'l' }}
|
||||
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)]"
|
||||
member.online === '1' ? 'bg-[var(--admin-success)]' : 'bg-[var(--admin-text-muted)]'
|
||||
}`}
|
||||
/>
|
||||
</div>
|
||||
@@ -133,15 +135,15 @@ export default async function ModTeamPage() {
|
||||
<p className="text-[9px] text-muted-foreground">Mod</p>
|
||||
</div>
|
||||
<span className="text-xs text-muted-foreground whitespace-nowrap">
|
||||
{member.online === "1"
|
||||
? "Online"
|
||||
{member.online === '1'
|
||||
? 'Online'
|
||||
: member.lastOnline
|
||||
? new Date(member.lastOnline * 1000).toLocaleDateString()
|
||||
: "—"}
|
||||
: '—'}
|
||||
</span>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user