diff --git a/src/routes/_authenticated/admin.tsx b/src/routes/_authenticated/admin.tsx index 94f6d10..994d093 100644 --- a/src/routes/_authenticated/admin.tsx +++ b/src/routes/_authenticated/admin.tsx @@ -136,10 +136,114 @@ function Admin() { } function Overview({ stats, messages, posts, projects, onTab }: { stats: AdminStats; messages: ContactMessage[]; posts: Array<{ id: string; title: string; published: boolean; views: number; created_at: string }>; projects: Project[]; onTab: (tab: string) => void }) { - return

Recent activity

{messages.slice(0,4).map((m) =>
New contact message from {m.name}
{new Date(m.created_at).toLocaleString()}
)}{posts.slice(0,4).map((p) =>
{p.published ? "Published" : "Drafted"}: {p.title}
{new Date(p.created_at).toLocaleString()} · {p.views} views
)}{projects.slice(0,2).map((p) =>
Project: {p.title}
Order {p.order_index}
)}{messages.length + posts.length + projects.length === 0 &&
No activity yet.
}

Quick actions

onTab("posts")} /> onTab("projects")} /> onTab("messages")} /> onTab("comments")} />

Operational status

; + return

Recent activity

{messages.slice(0,4).map((m) =>
New contact message from {m.name}
{new Date(m.created_at).toLocaleString()}
)}{posts.slice(0,4).map((p) =>
{p.published ? "Published" : "Drafted"}: {p.title}
{new Date(p.created_at).toLocaleString()} · {p.views} views
)}{projects.slice(0,2).map((p) =>
Project: {p.title}
Order {p.order_index}
)}{messages.length + posts.length + projects.length === 0 &&
No activity yet.
}

Quick actions

onTab("posts")} /> onTab("projects")} /> onTab("messages")} /> onTab("comments")} />
; } function QuickAction({ label, icon: Icon, onClick }: { label: string; icon: typeof FileText; onClick: () => void }) { return ; } -function Status({ label }: { label: string }) { return
{label} Protected
; } +type OperationalState = "checking" | "healthy" | "warning" | "error"; + +function OperationalStatus({ stats }: { stats: AdminStats }) { + const [states, setStates] = useState>({ + admin: { state: "checking", label: "Checking…" }, + mfa: { state: "checking", label: "Checking…" }, + supabase: { state: "checking", label: "Checking…" }, + analytics: { state: "checking", label: "Checking…" }, + }); + + const check = async () => { + setStates({ + admin: { state: "checking", label: "Checking…" }, + mfa: { state: "checking", label: "Checking…" }, + supabase: { state: "checking", label: "Checking…" }, + analytics: { state: "checking", label: "Checking…" }, + }); + + const { data: userData, error: userError } = await supabase.auth.getUser(); + const currentUser = userData.user; + + let adminHealthy = false; + if (currentUser && !userError) { + const { data: roles, error: rolesError } = await supabase + .from("user_roles") + .select("role") + .eq("user_id", currentUser.id); + adminHealthy = !rolesError && (roles ?? []).some((role) => role.role === "admin"); + } + + const { data: aalData, error: aalError } = await supabase.auth.mfa.getAuthenticatorAssuranceLevel(); + const mfaHealthy = !aalError && aalData.currentLevel === "aal2"; + + const { error: databaseError } = await supabase.from("profiles").select("id", { count: "exact", head: true }); + const supabaseHealthy = !databaseError; + + const analyticsLoaded = + typeof window !== "undefined" && + typeof (window as Window & { va?: unknown }).va === "function"; + + setStates({ + admin: { + state: adminHealthy ? "healthy" : "error", + label: adminHealthy ? "Verified" : "Not verified", + }, + mfa: { + state: mfaHealthy ? "healthy" : "warning", + label: mfaHealthy ? "AAL2 verified" : "Not AAL2", + }, + supabase: { + state: supabaseHealthy ? "healthy" : "error", + label: supabaseHealthy ? "Connected" : "Connection error", + }, + analytics: { + state: analyticsLoaded ? "healthy" : "warning", + label: analyticsLoaded ? "Loaded" : "Not detected", + }, + }); + }; + + useEffect(() => { + void check(); + }, []); + + const statusClass = (state: OperationalState) => + state === "healthy" + ? "text-emerald-400" + : state === "checking" + ? "text-muted-foreground" + : "text-amber-400"; + + const statusIcon = (state: OperationalState) => + state === "healthy" ? : null; + + return
+
+

Operational status

+ +
+
+ {[ + ["Admin authorization", states.admin], + ["MFA security", states.mfa], + ["Supabase connection", states.supabase], + ["Vercel Analytics", states.analytics], + ].map(([label, status]) => { + const item = status as { state: OperationalState; label: string }; + return
+ {label} + + {statusIcon(item.state)} + {item.label} + +
; + })} +
+
+ + +
+
; +} function Messages({ messages, refetch, onActivity }: { messages: ContactMessage[]; refetch: () => Promise; onActivity: (a: string, r: string, id?: string) => Promise; }) { const [expanded, setExpanded] = useState(null); const [filter, setFilter] = useState("all"); const visible = messages.filter((m) => filter === "all" || m.status === filter);