import { createDefaultForm } from "@/app/admin/form/actions"; import { AdminShellServer } from "@/components/admin-shell-server"; import { RealtimeRefresh } from "@/components/realtime-refresh"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Progress } from "@/components/ui/progress"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { getAdminDashboardData } from "@/lib/admin/admin-dashboard"; import { ArrowUpRight, ClipboardList, FilePlus2, Server, Upload, } from "lucide-react"; import Link from "next/link"; export const dynamic = "force-dynamic"; function formatNumber(value: number) { return new Intl.NumberFormat("en-US").format(value); } function formatDate(date: Date | null) { if (!date) return "No responses"; return date.toLocaleString("en-GB", { timeZone: "Asia/Bangkok", hour12: false, }); } function respondentName(submission: { userName: string | null; userDiscordId: string | null; }) { return submission.userName || submission.userDiscordId || "Anonymous"; } function MetricCard({ label, value, detail, }: { label: string; value: number; detail: string; }) { return ( {label} {formatNumber(value)} {detail} ); } function QuickAction({ href, title, description, icon: Icon, disabled = false, }: { href: string; title: string; description: string; icon: typeof ClipboardList; disabled?: boolean; }) { return ( {title} {description} {disabled ? ( ) : ( )} ); } export default async function AdminPage() { const { summary, recentSubmissions, activeForms } = await getAdminDashboardData(); const busiestFormResponses = Math.max( ...activeForms.map((form) => form.responsesLast7Days), 1, ); return (

Command center

Dashboard

Live form operations · Bangkok time

Responses today {formatNumber(summary.responsesToday)} Live

Submissions received since midnight. Realtime updates keep this workspace current while you are here.

{formatNumber(summary.responsesLast7Days)} this week {formatNumber(summary.openForms)} forms accepting responses
Recent responses The latest submissions across every form. {recentSubmissions.length === 0 ? (

Responses will appear here after someone submits a form.

) : ( <>
Respondent Form Submitted Status {recentSubmissions.map((submission) => ( {respondentName(submission)} {submission.formTitle} {formatDate(submission.submittedAt)} {submission.edited ? "Edited" : "Original"} ))}
{recentSubmissions.map((submission) => ( {respondentName(submission)} {submission.formTitle} · {formatDate(submission.submittedAt)} {submission.edited ? "Edited" : "Original"} ))}
)}
Form momentum Response activity during the last 7 days. {activeForms.length === 0 ? (

Create a form to start tracking activity.

) : ( activeForms.map((form) => (
{form.title} {formatNumber(form.responsesLast7Days)}
{form.isOpen ? "Open" : "Closed"} {formatNumber(form.totalResponses)} total
)) )}

Workspace

Go directly to the tools you operate most often.

); }