import { Ago, Avatar, Badge, Empty, LayerCard, Link, Table, cn, formatDate } from "@refs/design-system"; import type { AdminDay } from "@refs/backend/contract"; import { useSearchParams } from "react-router"; import type { Route } from "./+types/admin"; import { AppShell, PageHeader } from "../components/shell"; import { found, nowSeconds, signedIn } from "../lib/session"; export const meta: Route.MetaFunction = () => [{ title: "Admin ยท refs" }]; export async function loader({ context }: Route.LoaderArgs) { return { overview: await found(signedIn(context).adminOverview()), now: nowSeconds() }; } const METRICS: { key: Exclude; label: string }[] = [ { key: "active", label: "Active people" }, { key: "signups", label: "Sign-ups" }, { key: "agentSessions", label: "Agent sessions" }, { key: "events", label: "Events" }, ]; const NUMBER = new Intl.NumberFormat("en-US"); function Stat({ label, value, detail }: { label: string; value: number; detail?: string }) { return (
{label} {NUMBER.format(value)} {detail && {detail}}
); } function DailyChart({ days }: { days: readonly AdminDay[] }) { const [search] = useSearchParams(); const metric = METRICS.find((candidate) => candidate.key === search.get("metric")) ?? METRICS[0]; const values = days.map((day) => day[metric.key]); const peak = Math.max(1, ...values); const total = values.reduce((sum, value) => sum + value, 0); return ( Last 30 days {metric.label}: {NUMBER.format(total)} in 30 days, peak {NUMBER.format(Math.max(...values))} a day
{days.map((day) => (
))}
{days[0]?.day} {days.at(-1)?.day}
); } function Ranked({ title, rows, empty }: { title: string; rows: { label: string; count: number }[]; empty: string }) { const peak = Math.max(1, ...rows.map((row) => row.count)); return ( {title} {rows.length === 0 ? ( ) : (
    {rows.map((row) => (
  • {row.label} {NUMBER.format(row.count)}
  • ))}
)}
); } export default function Admin({ loaderData }: Route.ComponentProps) { const { overview, now } = loaderData; const { totals, people } = overview; return (
({ label: row.runtime, count: row.sessions }))} empty="No agent sessions yet" /> ({ label: row.kind, count: row.count }))} empty="No actions yet" />
People {people.length === 0 ? ( ) : (
Person Joined Last seen Last agent Repos Pulls Agents Events {people.map((person) => ( {person.handle ? ( {person.name} ) : ( {person.name} )} {person.status === "waitlisted" && Not signed in yet} {person.email} {formatDate(person.joinedAt)} {person.lastSeenAt ? : "Not recorded"} {person.lastAgentAt ? : "Never"} {person.repos} {person.pulls} {person.agentSessions} {person.events} ))}
)}
); }