import Link from "next/link"; import { getTranslations } from "next-intl/server"; import { DataTable } from "@/components/admin/data-table"; import { Badge } from "@/components/ui/badge"; import { requireModPermission } from "@/lib/admin/guard"; import { calcPagination, parseListParams } from "@/lib/admin-helpers"; import { getAvatarUrl } from "@/lib/imager"; import { PERMS } from "@/lib/permissions"; import { prisma } from "@/lib/prisma"; import type { DataTableColumn } from "@/types/common"; export const dynamic = "force-dynamic"; type ModUserRow = { id: number; username: string; rank: number; online: string; motto: string; look: string; lastLogin: number | null; }; const columns: DataTableColumn[] = [ { key: "id", label: "ID", sortable: true }, { key: "username", label: "User", sortable: true, render: (_, row) => (
{row.username}
), }, { key: "rank", label: "Rank", sortable: true, render: (v) => #{String(v)}, }, { key: "online", label: "Online", render: (v) => v === "1" ? ( Online ) : ( Offline ), }, { key: "motto", label: "Motto", render: (v) => ( {String(v || "—")} ), }, { key: "actions", label: "", render: (_, row) => (
Mod view Public
), }, ]; export default async function ModUsersPage({ searchParams, }: { searchParams: Promise>; }) { await requireModPermission([PERMS.MOD_USERS_VIEW, PERMS.USERS_VIEW]); const t = await getTranslations("pages.mod"); const raw = await searchParams; const parsed = parseListParams(new URLSearchParams(raw)); const where = parsed.search.trim() ? { OR: [ { username: { contains: parsed.search.trim() } }, { motto: { contains: parsed.search.trim() } }, ...(Number.isFinite(Number(parsed.search)) && Number(parsed.search) > 0 ? [{ id: Number(parsed.search) }] : []), ], } : {}; const orderBy = parsed.sort ? { [parsed.sort]: parsed.order } : { id: "desc" as const }; const [total, users] = await Promise.all([ prisma.user.count({ where }).catch(() => 0), prisma.user .findMany({ where, orderBy, skip: (parsed.page - 1) * parsed.perPage, take: parsed.perPage, select: { id: true, username: true, rank: true, online: true, motto: true, look: true, lastLogin: true, }, }) .catch(() => []), ]); const pagination = calcPagination(total, parsed.page, parsed.perPage); const rows: ModUserRow[] = users; return (

{t("usersTitle")}

{t("usersSubtitle")}

{total === 0 && !parsed.search ? (
{t("usersEmpty")}
) : ( )}
); }