import React, { useState } from 'react' import { createFileRoute, Outlet, useNavigate, useLocation, Navigate } from '@tanstack/react-router' import { LayoutDashboard, Package, DollarSign, Group, Images, CalendarClock, TriangleAlert, ShoppingBag, TicketPercent, Code2, Store, Users, Megaphone, LogOut, Menu, ArrowLeft, RefreshCw, UserRound, } from 'lucide-react' import { p as MyText } from 'web-components' import { useStaffAuth } from '../components/context/staff-auth-context' import { EventBus, REFRESH_EVENT } from '../lib/event-bus' export const Route = createFileRoute('/dashboard')({ component: DashboardShell, }) const SCREEN_TITLES: Record = { products: 'Products', prices: 'Prices Overview', 'product-groupings': 'Product Groupings', banners: 'Dashboard Banners', slots: 'Slots', complaints: 'Complaints', orders: 'Manage Orders', coupons: 'Coupons', 'vendor-snippets': 'Vendor Snippets', stores: 'Stores', users: 'User Management', notifications: 'Send Notifications', 'product-tags': 'Product Tags', rebalance: 'Rebalance Orders', 'customize-app': 'Customize App', } interface SidebarEntry { label: string to: string icon: React.ReactNode action?: 'logout' } const SIDEBAR_ENTRIES: SidebarEntry[] = [ { label: 'Dashboard', to: '/dashboard', icon: }, { label: 'Products', to: '/dashboard/products', icon: }, { label: 'Prices Overview', to: '/dashboard/prices', icon: }, { label: 'Product Groupings', to: '/dashboard/product-groupings', icon: }, { label: 'Dashboard Banners', to: '/dashboard/banners', icon: }, { label: 'Slots', to: '/dashboard/slots', icon: }, { label: 'Complaints', to: '/dashboard/complaints', icon: }, { label: 'Manage Orders', to: '/dashboard/orders', icon: }, { label: 'Coupons', to: '/dashboard/coupons', icon: }, { label: 'Vendor Snippets', to: '/dashboard/vendor-snippets', icon: }, { label: 'Stores', to: '/dashboard/stores', icon: }, { label: 'User Management', to: '/dashboard/users', icon: }, { label: 'Send Notifications', to: '/dashboard/notifications', icon: }, { label: 'Logout', to: '/login', icon: , action: 'logout' }, ] // Top-level feature roots show the menu toggle; deeper screens show back. const FEATURE_ROOTS = new Set([ '/dashboard', ...SIDEBAR_ENTRIES.filter((e) => !e.action).map((e) => e.to), ]) function DashboardShell() { const { isLoggedIn, isLoading, staff, logout } = useStaffAuth() const navigate = useNavigate() const location = useLocation() const [sidebarOpen, setSidebarOpen] = useState(false) if (isLoading) { return (
) } if (!isLoggedIn) { return } const pathname = location.pathname const segment = pathname.split('/')[2] ?? '' const title = segment ? (SCREEN_TITLES[segment] ?? 'Dashboard') : 'Dashboard' const canGoBack = !FEATURE_ROOTS.has(pathname) const goEntry = (entry: SidebarEntry) => { if (entry.action === 'logout') { logout() } else if (entry.to === '/dashboard') { navigate({ to: '/dashboard' }) } else { navigate({ to: entry.to } as any) } setSidebarOpen(false) } const isActive = (to: string) => to === '/dashboard' ? pathname === '/dashboard' : pathname.startsWith(to) const sidebar = (
{staff && (
{staff.name} Staff Member
)}
) return (
{/* Desktop sidebar */} {/* Mobile drawer */} {sidebarOpen && (
setSidebarOpen(false)} />
)}
{/* Header — same chrome as admin-ui drawer header */}
{title}
) }