"use client"; import { usePoll } from "@/lib/use-poll"; import type { EmailStats } from "@/lib/types"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { StatusBadge } from "@/components/status-badge"; interface BackupResult { host: string; status: string; last_run: string; size?: string; } interface DriftResult { stack: string; drifted: boolean; details?: string; } interface StackRestart { stack: string; status: string; timestamp: string; } export default function AutomationsPage() { const { data: emails } = usePoll( "/api/automations/email", 60000 ); const { data: backups } = usePoll>( "/api/automations/backup", 120000 ); const { data: drift } = usePoll>( "/api/automations/drift", 120000 ); const { data: restartsData } = usePoll<{ entries: StackRestart[] }>( "/api/automations/restarts", 60000 ); const restarts = restartsData?.entries ?? []; return (

Automations

{/* Email Organizers */} Email Organizers {!emails ? (

Loading...

) : (
{emails.accounts.map((acct: Record) => { const name = String(acct.account ?? acct.name ?? "?"); const today = Number(acct.today ?? acct.today_total ?? 0); const cats = (acct.categories ?? acct.today_categories ?? {}) as Record; return (
{name} {today} today
{Object.entries(cats).map(([cat, count]) => ( {cat}: {count} ))}
); })}
)}
{/* Row 2: Backups, Drift, Restarts */}
Backup Status {!backups ? (

Loading...

) : (
{backups.has_errors ? (

Errors detected in backup

) : null}

{String(backups.entries ?? 0)} log entries today

)}
Config Drift {!drift ? (

Loading...

) : (

{String(drift.last_result ?? "No scan results yet")}

)}
Stack Restarts {!restarts ? (

Loading...

) : restarts.length === 0 ? (

No recent restarts

) : (
{restarts.map((r, i) => (
{r.stack}
{new Date(r.timestamp).toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit", })}
))}
)}
); }