"use client"; import { GitGraph, LogOut, type LucideIcon, Network, Server, Users } from "lucide-react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { useEffect } from "react"; import { BrandLockup } from "@/components/brand"; import { FullScreenLoader } from "@/components/page-layout"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Sidebar, SidebarContent, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInset, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarProvider, SidebarTrigger, } from "@/components/ui/sidebar"; import { signOut, useSession } from "@/lib/auth-client"; type NavigationGroup = { label: string; items: Array<{ href: string; icon: LucideIcon; label: string; context: string; }>; }; const navigation: NavigationGroup[] = [ { label: "Operations", items: [ { href: "/dashboard/users", icon: Users, label: "Users", context: "Identity" }, { href: "/dashboard/servers", icon: Server, label: "Servers", context: "Workloads" }, { href: "/dashboard/topology", icon: GitGraph, label: "Network", context: "Topology" }, ], }, { label: "Kubernetes", items: [{ href: "/dashboard/k8s", icon: Network, label: "Resources", context: "Cluster" }], }, ]; export function DashboardLayout({ children }: { children: React.ReactNode }) { const pathname = usePathname(); const router = useRouter(); const { data: session, isPending } = useSession(); useEffect(() => { if (!isPending && !session?.user) { router.replace("/login"); } }, [session, isPending, router]); if (isPending || !session?.user) return ; const handleSignOut = async () => { await signOut(); window.location.href = "/login"; }; const userInitials = session?.user?.name ?.split(" ") .map((n) => n[0]) .join("") .toUpperCase() || "U"; const currentPage = navigation .flatMap((group) => group.items) .find((item) => pathname === item.href || pathname.startsWith(`${item.href}/`)); return ( {navigation.map((group) => ( {group.label} {group.items.map((item) => ( {item.label} ))} ))}
Sign Out
{currentPage ? `${currentPage.context} / ${currentPage.label}` : "Control plane"}
{children}
); }