import React, { useState, useEffect } from "react"; import type { User, Asset } from "../../../types"; import { apiClient } from "../../../lib/api-client"; import { Users, FileStack, DownloadCloud, AlertTriangle, Cpu, Terminal, Brain, Server, ShieldCheck, } from "lucide-react"; export const AnalyticsDashboard: React.FC = () => { const [clients, setClients] = useState([]); const [assets, setAssets] = useState([]); const [loading, setLoading] = useState(true); const fetchStats = async () => { setLoading(true); try { const clientRes = await apiClient.get("/admin/clients"); const assetRes = await apiClient.get("/assets"); setClients(clientRes.data); setAssets(assetRes.data); } catch (err) { console.error(err); } finally { setLoading(false); } }; useEffect(() => { fetchStats(); }, []); // Compute analytics data const totalClients = clients.length; const totalAssets = assets.length; const totalDownloads = assets.reduce((sum, a) => sum + a.downloadsCount, 0); const pendingApprovals = clients.filter( (c) => c.onboardingStatus === "PENDING_APPROVAL", ).length; // Category counts const categoryCounts = assets.reduce( (acc, a) => { acc[a.categoryId] = (acc[a.categoryId] || 0) + 1; return acc; }, { silicon: 0, software: 0, ai: 0, cloud: 0 } as Record, ); const categoryMax = Math.max(...Object.values(categoryCounts), 1); // Onboarding Status distributions const onboardingCounts = clients.reduce( (acc, c) => { acc[c.onboardingStatus] = (acc[c.onboardingStatus] || 0) + 1; return acc; }, { NOT_STARTED: 0, FORM_COMPLETED: 0, NDA_SIGNED: 0, PENDING_APPROVAL: 0, APPROVED: 0, REJECTED: 0, } as Record, ); const onboardingMax = Math.max(...Object.values(onboardingCounts), 1); return (

Operational Analytics

Overview of client onboarding metrics, asset repository distribution, and core library downloads.

{loading ? (
{[1, 2, 3, 4].map((n) => (
))}
) : ( /* Metric Cards */

Total Clients

{totalClients}

Active Assets

{totalAssets}

Total Downloads

{totalDownloads}

0 ? "bg-warning/10 text-warning" : "bg-success/10 text-success"}`} >

Pending Review

{pendingApprovals}

)} {/* Charts Grid */}
{/* Category Breakdown */}

Assets by Domain Category

Count
{loading ? (
{[1, 2, 3].map((n) => (
))}
) : (
{[ { key: "silicon", name: "Silicon Core IP", icon: Cpu }, { key: "software", name: "Software & Libraries", icon: Terminal, }, { key: "ai", name: "AI & Agent Workflows", icon: Brain }, { key: "cloud", name: "Cloud Configs & IaC", icon: Server }, ].map((item) => { const count = categoryCounts[item.key] || 0; const percentage = (count / categoryMax) * 100; const Icon = item.icon; return (
{item.name} {count}
); })}
)}
{/* Client Onboarding Funnel */}

Client Onboarding Funnel

Accounts
{loading ? (
{[1, 2, 3].map((n) => (
))}
) : (
{[ { key: "NOT_STARTED", name: "Registration Initiated" }, { key: "FORM_COMPLETED", name: "Profile Form Saved" }, { key: "NDA_SIGNED", name: "NDA Document Signed" }, { key: "PENDING_APPROVAL", name: "Awaiting Admin Approval" }, { key: "APPROVED", name: "Approved & Active Portal" }, ].map((item) => { const count = onboardingCounts[item.key] || 0; const percentage = (count / onboardingMax) * 100; return (
{item.name} {count}
); })}
)}
{/* Bottom list showing Top Downloaded Assets */}

Most Downloaded Catalog Resources

{assets .slice() .sort((a, b) => b.downloadsCount - a.downloadsCount) .slice(0, 3) .map((asset, index) => (
{index + 1}

{asset.title}

{asset.subcategory}

{asset.downloadsCount}{" "} downloads
))}
); };