'use client'; import { useState, useRef, useEffect } from 'react'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; interface AdminMenuItem { name: string; href: string; icon: string; description: string; } const adminMenuItems: AdminMenuItem[] = [ { name: 'Users', href: '/dashboard/admin/users', icon: '👥', description: 'Manage users and permissions', }, { name: 'Organizations', href: '/dashboard/admin/organizations', icon: '🏢', description: 'Manage organizations and companies', }, { name: 'Bookings', href: '/dashboard/admin/bookings', icon: '📦', description: 'View and manage all bookings', }, { name: 'Documents', href: '/dashboard/admin/documents', icon: '📄', description: 'Manage organization documents', }, { name: 'CSV Rates', href: '/dashboard/admin/csv-rates', icon: '📊', description: 'Upload and manage CSV rates', }, ]; export default function AdminPanelDropdown() { const [isOpen, setIsOpen] = useState(false); const dropdownRef = useRef(null); const pathname = usePathname(); // Close dropdown when clicking outside useEffect(() => { function handleClickOutside(event: MouseEvent) { if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) { setIsOpen(false); } } if (isOpen) { document.addEventListener('mousedown', handleClickOutside); } return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, [isOpen]); // Close dropdown when route changes useEffect(() => { setIsOpen(false); }, [pathname]); const isActiveRoute = adminMenuItems.some(item => pathname.startsWith(item.href)); return (
{/* Trigger Button */} {/* Dropdown Menu */} {isOpen && (
{adminMenuItems.map(item => { const isActive = pathname.startsWith(item.href); return ( {item.icon}
{item.name}
{item.description}
); })}
)}
); }