/** * @deprecated Use AdminSidebar instead. AdminHeader is deprecated and will be removed. * The AdminSidebar provides the complete navigation system for admin pages. * It includes an expandable Settings sub-menu with all settings pages. */ "use client"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { usePathname } from "next/navigation"; import { useState, useEffect, useRef } from "react"; import { authClient } from "@/lib/auth-client"; type AdminHeaderProps = { userRole?: string | null; canManageUsers?: boolean; routeTraceEnabled?: boolean; }; type NavLink = { href: string; label: string; external?: boolean; }; type SettingsItem = { href: string; label: string; description: string; }; const SETTINGS_ITEMS: SettingsItem[] = [ { href: "/admin/settings", label: "General", description: "Brand name, logo, timezone" }, { href: "/admin/settings/apps", label: "Add-ons", description: "Enable and manage feature add-ons" }, { href: "/admin/settings/billing", label: "Billing & Plans", description: "Subscription, invoices, usage" }, { href: "/admin/settings/payments", label: "Payments", description: "Stripe, Square, payment methods" }, { href: "/admin/communications/abandoned-carts", label: "Abandoned Cart Recovery", description: "3-email recovery sequence, recovered carts" }, { href: "/admin/communications/welcome-sequence", label: "Welcome Sequence", description: "4-email onboarding for new subscribers" }, ]; const BASE_NAV_LINKS: NavLink[] = [ { href: "/admin/orders", label: "Orders" }, { href: "/admin/stops", label: "Stops & Routes" }, { href: "/admin/products", label: "Products" }, { href: "/admin/time-tracking", label: "Time Tracking" }, { href: "/admin/communications", label: "Harvest Reach" }, ]; const EMPLOYEE_NAV_LINKS: NavLink[] = [ { href: "/admin/wholesale", label: "Wholesale" }, { href: "/admin/pickup", label: "Pickup" }, { href: "/wholesale/employee", label: "Pickup Portal", external: true }, ]; export default function AdminHeader({ userRole, canManageUsers, routeTraceEnabled }: AdminHeaderProps) { const router = useRouter(); const pathname = usePathname(); const isStoreEmployee = userRole === "store_employee"; const [settingsOpen, setSettingsOpen] = useState(false); const settingsRef = useRef(null); // Close dropdown on outside click useEffect(() => { function handleClick(e: MouseEvent) { if (settingsRef.current && !settingsRef.current.contains(e.target as Node)) { setSettingsOpen(false); } } document.addEventListener("mousedown", handleClick); return () => document.removeEventListener("mousedown", handleClick); }, []); // Close dropdown on route change useEffect(() => { // eslint-disable-next-line react-hooks/set-state-in-effect setSettingsOpen(false); }, [pathname]); const moduleLinks: NavLink[] = routeTraceEnabled ? [{ href: "/admin/route-trace", label: "Route Trace" }] : []; const fullNavLinks = BASE_NAV_LINKS.concat( userRole === "platform_admin" ? [{ href: "/admin/command-center", label: "Command Center" }] : [] ).concat(moduleLinks); const navLinks = isStoreEmployee ? EMPLOYEE_NAV_LINKS : fullNavLinks; const homeHref = isStoreEmployee ? "/admin/wholesale" : "/admin"; const homeLabel = isStoreEmployee ? "Pickup" : "Admin"; async function handleLogout() { document.cookie = "dev_session=;path=/;max-age=0"; await authClient.signOut(); router.push("/login"); router.refresh(); } const roleLabel = userRole === "platform_admin" ? "Platform Admin" : userRole === "brand_admin" ? "Brand Admin" : userRole === "store_employee" ? "Store Employee" : null; const isActive = (href: string) => { if (href === "/admin") return pathname === "/admin"; if (href === "/admin/settings") { return pathname === "/admin/settings" || pathname.startsWith("/admin/settings/"); } return pathname.startsWith(href); }; const isSettingsActive = pathname.startsWith("/admin/settings") || pathname === "/admin/settings" || pathname.startsWith("/admin/communications/abandoned-carts") || pathname.startsWith("/admin/communications/welcome-sequence"); return (
{/* Logo mark */}
{homeLabel}
{roleLabel && (
{roleLabel}
)}
); }