Swept the whole housekeeping panel (34 pages) so it's a consistent, improved adaptation of the old Filament admin rather than bare tables: - Live status tiles (StatusCard) summarising each page's data — counts and stateful metrics (users online, active/permanent bans, pending applications, settings, radio shouts, etc.). - Status pills (admin-badge ok/danger) replacing ad-hoc text: online/ offline, account/ip ban types, permanent vs timed, command OK/FAIL, alert severity & read/new, enabled/disabled, open/closed. - Sections wrapped in .admin-section with h2 headers; redundant inline table styling removed (the global .admin layer handles it). - alerts/logs/emulator hand-built as the reference pattern; the rest via parallel agents that read the schema and preserved every server action, query and field name. Behaviour unchanged (same actions, queries, field names). Verified in a real authed admin session (prod, amx_test): pages render with live data (Users tiles show 7 real accounts + online/offline pills), no errors. tsc 0, vitest 49/49, next build 0.
118 lines
3.5 KiB
TypeScript
118 lines
3.5 KiB
TypeScript
import Link from "next/link";
|
|
import { StatusCard } from "@/components/admin/dashboard";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
const PER_PAGE = 25;
|
|
|
|
export default async function AdminUsers({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{ q?: string; page?: string }>;
|
|
}) {
|
|
const sp = await searchParams;
|
|
const q = (sp.q ?? "").trim();
|
|
const page = Math.max(1, Number(sp.page ?? "1") || 1);
|
|
const where = q ? { username: { contains: q } } : {};
|
|
|
|
// .catch(...) keeps the precise selected-row type while falling back to an
|
|
// empty page when the DB is unavailable (instead of a 500).
|
|
const users = await prisma.user
|
|
.findMany({
|
|
where,
|
|
select: { id: true, username: true, rank: true, credits: true, online: true },
|
|
orderBy: { id: "desc" },
|
|
skip: (page - 1) * PER_PAGE,
|
|
take: PER_PAGE,
|
|
})
|
|
.catch(() => []);
|
|
const total = await prisma.user.count({ where }).catch(() => 0);
|
|
const pages = Math.max(1, Math.ceil(total / PER_PAGE));
|
|
|
|
const onlineOnPage = users.filter((u) => u.online === "1").length;
|
|
|
|
return (
|
|
<main>
|
|
<h1>Users</h1>
|
|
<p className="muted" style={{ marginTop: "-0.4rem" }}>
|
|
{q ? `Search results for “${q}”.` : "Most recent accounts first."}
|
|
</p>
|
|
|
|
<div className="admin-stats">
|
|
<StatusCard label="Total users" value={total} icon="👥" />
|
|
<StatusCard label="On this page" value={users.length} icon="📄" />
|
|
<StatusCard
|
|
label="Online (page)"
|
|
value={onlineOnPage}
|
|
state={onlineOnPage > 0 ? "ok" : "neutral"}
|
|
icon="🟢"
|
|
/>
|
|
</div>
|
|
|
|
<form
|
|
className="card"
|
|
style={{ display: "flex", gap: "0.5rem", marginBottom: "1.5rem", flexWrap: "wrap" }}
|
|
>
|
|
<input
|
|
name="q"
|
|
defaultValue={q}
|
|
placeholder="Search username"
|
|
style={{ flex: 1, minWidth: 200 }}
|
|
/>
|
|
<button type="submit" className="btn btn-primary">
|
|
Search
|
|
</button>
|
|
</form>
|
|
|
|
<section className="admin-section">
|
|
<h2>Accounts ({total})</h2>
|
|
{users.length === 0 ? (
|
|
<p className="muted">No users match this search.</p>
|
|
) : (
|
|
<div style={{ overflowX: "auto" }}>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Username</th>
|
|
<th>Rank</th>
|
|
<th>Credits</th>
|
|
<th>Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{users.map((u) => (
|
|
<tr key={u.id}>
|
|
<td className="muted">{u.id}</td>
|
|
<td>
|
|
<Link href={`/admin/users/${u.id}`}>{u.username}</Link>
|
|
</td>
|
|
<td>{u.rank}</td>
|
|
<td>{u.credits}</td>
|
|
<td>
|
|
<span className={`admin-badge ${u.online === "1" ? "ok" : ""}`}>
|
|
{u.online === "1" ? "online" : "offline"}
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
</section>
|
|
|
|
<p className="muted">
|
|
Page {page} / {pages} · {total} users
|
|
{page < pages ? (
|
|
<>
|
|
{" · "}
|
|
<Link href={`/admin/users?q=${encodeURIComponent(q)}&page=${page + 1}`}>Next →</Link>
|
|
</>
|
|
) : null}
|
|
</p>
|
|
</main>
|
|
);
|
|
}
|