"use client"; import React, { useState, useEffect } from "react"; import { cmsApi } from "@/lib/api"; import { Building2, Users, BookOpen, Zap, Server, Clock, ShieldAlert, Gauge, TrendingUp } from "lucide-react"; interface TokenStats { total_tokens: number; total_requests: number; total_cost_usd: number; } export default function AdminDashboard() { const [stats, setStats] = useState({ orgs: 0, users: 0, courses: 0 }); const [tokenStats, setTokenStats] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const fetchStats = async () => { try { // In a real app we'd have a specific stats endpoint, // but for now we'll calculate from lists const [org, users, tokenResp] = await Promise.all([ cmsApi.getOrganization(), cmsApi.getAllUsers(), fetch(`${process.env.NEXT_PUBLIC_CMS_API_URL || 'http://localhost:3001'}/admin/token-usage`, { headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}`, }, }) ]); setStats({ orgs: 1, // Single tenant architecture users: users.length, courses: 0 // We'd need a global courses count }); // Load token stats if (tokenResp.ok) { const tokenData = await tokenResp.json(); setTokenStats({ total_tokens: tokenData.stats?.total_tokens || 0, total_requests: tokenData.stats?.total_requests || 0, total_cost_usd: tokenData.stats?.total_cost_usd || 0, }); } } catch (err) { console.error("Failed to load admin stats", err); } finally { setLoading(false); } }; fetchStats(); }, []); const cards = [ { label: "Organizations", value: stats.orgs, icon: Building2, color: "text-blue-600 dark:text-blue-400", bg: "bg-blue-500/10", desc: "Active institutional tenants" }, { label: "Total Users", value: stats.users, icon: Users, color: "text-purple-600 dark:text-purple-400", bg: "bg-purple-500/10", desc: "Registered globally" }, { label: "Global Courses", value: stats.courses, icon: BookOpen, color: "text-green-600 dark:text-green-400", bg: "bg-green-500/10", desc: "Managed across all orgs" }, ]; return (

System Overview

Holistic view of the OpenCCB ecosystem.

{/* Stat Grid */}
{cards.map((card) => (
{card.label}
{loading ? "..." : card.value}

{card.desc}

))} {/* AI Token Usage Card */}
AI Token Usage
{loading ? "..." : tokenStats ? new Intl.NumberFormat('en-US', { notation: 'compact', compactDisplay: 'short' }).format(tokenStats.total_tokens) : 'N/A'}

{tokenStats ? `${new Intl.NumberFormat('en-US').format(tokenStats.total_requests)} requests • $${tokenStats.total_cost_usd.toFixed(2)}` : 'Loading...'}

View Details
{/* System Health */}

Service Status

All systems operational
API Services (CMS/LMS)
Rust Axum Cluster
Online
Local AI Services
Whisper + Ollama
Online
Background Workers
Notification Scheduler
Running
Security Engine
JWT & RBAC Middleware
Active
); }