"use client"; import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { ShieldHalf, Building2, CreditCard, FileText, LogOut, BarChart3, PieChart, RefreshCw, LifeBuoy, LayoutGrid, } from "lucide-react"; import { api, clearToken } from "@/lib/api"; const nav = [ { href: "/admin", label: "Dashboard", icon: LayoutGrid }, { href: "/admin/organizations", label: "Organizations", icon: Building2 }, { href: "/admin/utilization", label: "Utilization", icon: PieChart }, { href: "/admin/retention", label: "Retention", icon: RefreshCw }, { href: "/admin/plans", label: "Plans & Pricing", icon: CreditCard }, { href: "/admin/revenue", label: "Revenue", icon: BarChart3 }, { href: "/admin/support", label: "Support View", icon: LifeBuoy }, { href: "/admin/audit", label: "Audit Logs", icon: FileText }, ]; export default function AdminLayout({ children }: { children: React.ReactNode }) { const router = useRouter(); const [me, setMe] = useState(null); useEffect(() => { api("/me") .then((m) => { if (!m.is_product_admin) { router.replace("/dashboard"); return; } setMe(m); }) .catch(() => { clearToken(); router.replace("/login"); }); }, [router]); if (!me) return
Loading…
; function logout() { clearToken(); window.location.href = "/login"; } return (
{children}
); }