import React, { useEffect, useMemo, useRef, useState } from 'react'; import { Link, Outlet, useLocation, useNavigate } from 'react-router-dom'; import { motion } from 'framer-motion'; import { Activity, Bell, Bike, Car, ChevronDown, Coins, FileSpreadsheet, FileText, ListTodo, LogOut, Menu, Search, Settings, Shield, ShieldAlert, User, UserCheck, Warehouse, } from 'lucide-react'; import { cn } from '@/lib/utils'; import { DOORMILE_MARK_URL } from '@/assets/brand'; import { Avatar } from '@/components/ds/Avatar'; import { Badge } from '@/components/ui/badge'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Sheet, SheetContent, SheetHeader, SheetTitle } from '@/components/ui/sheet'; import { useAuth } from '@/lib/AuthContext'; import { useExceptions } from '@/lib/doormileHooks'; import { formatDoormileTimestamp } from '@/lib/doormileTimestamp'; import AIPanel from '@/components/assistant/DoormileAI/AIPanel'; import AILauncher from '@/components/assistant/DoormileAI/AILauncher'; /** * The console shell. * * Single 56px header bar, compact search with a keyboard shortcut, hairline tab * indicator, mobile sheet. * * Core destinations sit on the bar; the rest live in two grouped menus on it * (Fleet Ops, Reports) plus a Settings section inside the account menu, which * holds the two destinations that are configuration rather than operations * (Pricing Matrix, Customers Directory). * * Said precisely because the previous wording — "three grouped menus (Fleet * Ops, Reports, Settings)" — sent a reader looking for a third NAV_GROUPS * entry that does not exist, and hid the fact that the Settings pair is * reached by a different route from everything else. That difference is * exactly what made them unreachable on mobile. */ const ROOT = '/doormile'; const LOGO_FILTER = { filter: 'brightness(0) saturate(100%) invert(15%) sepia(93%) saturate(5437%) hue-rotate(346deg) brightness(81%) contrast(92%)', }; /** Destinations that sit directly on the header bar. */ const NAV = [ { label: 'Control X', path: '/doormile/control-x' }, { label: 'Bookings', path: '/doormile/bookings' }, { label: 'Orders', path: '/doormile/orders' }, { label: 'Deliveries', path: '/doormile/deliveries' }, { label: 'Milers', path: '/doormile/milers' }, { label: 'Clients', path: '/doormile/tenants' }, ]; /** Destinations grouped behind a menu, in the order the console lists them. */ const NAV_GROUPS = [ { label: 'Fleet Ops', items: [ { label: 'Hubs', path: '/doormile/hubs', icon: Warehouse }, { label: 'Vehicles', path: '/doormile/vehicles', icon: Car }, { label: 'Tripsheets', path: '/doormile/tripsheets', icon: ListTodo }, { label: 'Exceptions', path: '/doormile/exceptions', icon: ShieldAlert }, { label: 'Competitive Intel', path: '/doormile/competitive-intel', icon: Activity }, { label: 'App Users', path: '/doormile/app-users', icon: UserCheck }, ], }, { label: 'Reports', items: [ { label: 'Orders Summary', path: '/doormile/reports/orderssummary', icon: FileSpreadsheet }, { label: 'Orders Details', path: '/doormile/reports/ordersdetails', icon: FileText }, { label: 'Milers Summary', path: '/doormile/reports/riderssummary', icon: Bike }, { label: 'Profitability', path: '/doormile/reports/profitability', icon: Coins }, ], }, ]; function GlobalSearch() { const navigate = useNavigate(); const [query, setQuery] = useState(''); const [focused, setFocused] = useState(false); const inputRef = useRef(null); /* Cmd/Ctrl+K focuses search — jump-to control shortcut */ useEffect(() => { const onKey = (e) => { if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') { e.preventDefault(); inputRef.current?.focus(); } }; window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, []); return (
{ e.preventDefault(); /* Orders is the console's search surface: it holds every booking, and an operator searching from the header is nearly always chasing one order number or one customer. */ if (query.trim()) navigate(`/doormile/orders?search=${encodeURIComponent(query.trim())}`); }} role="search" className={cn( 'relative hidden items-center transition-all duration-base ease-out md:flex', focused || query ? 'w-64' : 'w-44' )} >