"use client"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import AccountMenu from "@/components/AccountMenu"; import { useAuth } from "@/components/AuthProvider"; import { navItems, type NavItem } from "@/data/home"; import { getDisplayName } from "@/lib/userName"; import styles from "./DashboardShell.module.css"; const websiteUrl = process.env.NEXT_PUBLIC_WEBSITE_URL?.replace(/\/$/, "") || "http://localhost:3000"; function hrefMatches(href: string, pathname: string) { return pathname === href || pathname.startsWith(`${href}/`); } function activeChildHref( children: { href: string }[], pathname: string, ) { let best = ""; for (const child of children) { if (!hrefMatches(child.href, pathname)) continue; if (child.href.length > best.length) best = child.href; } return best; } function groupActive(item: Extract, pathname: string) { return activeChildHref(item.children, pathname) !== ""; } export default function DashboardShell({ children, }: { children: React.ReactNode; }) { const pathname = usePathname(); const router = useRouter(); const { user, logout } = useAuth(); const [menuOpen, setMenuOpen] = useState(false); const [openGroup, setOpenGroup] = useState(() => { const active = navItems.find( (item) => item.type === "group" && groupActive(item, pathname), ); return active?.type === "group" ? active.label : null; }); const displayName = getDisplayName(user); useEffect(() => { const active = navItems.find( (item) => item.type === "group" && groupActive(item, pathname), ); if (active?.type === "group") setOpenGroup(active.label); }, [pathname]); return (
{menuOpen ? (

Admin workspace

Marketplace control

{children}
); }