import { Outlet, Link, useNavigate, useLocation } from 'react-router-dom' import { useAuthStore } from '@/store/auth' import { LogOut, Menu, LayoutDashboard, HardDrive, Database, Network, Settings, Bell, Server, Users, Archive } from 'lucide-react' import { useState, useEffect } from 'react' export default function Layout() { const { user, clearAuth } = useAuthStore() const navigate = useNavigate() const location = useLocation() const [sidebarOpen, setSidebarOpen] = useState(false) // Set sidebar open by default on desktop, closed on mobile useEffect(() => { const handleResize = () => { if (window.innerWidth >= 1024) { setSidebarOpen(true) } else { setSidebarOpen(false) } } handleResize() // Set initial state window.addEventListener('resize', handleResize) return () => window.removeEventListener('resize', handleResize) }, []) const handleLogout = () => { clearAuth() navigate('/login') } const navigation = [ { name: 'Dashboard', href: '/', icon: LayoutDashboard }, { name: 'Storage', href: '/storage', icon: HardDrive }, { name: 'Tape Libraries', href: '/tape', icon: Database }, { name: 'iSCSI Management', href: '/iscsi', icon: Network }, { name: 'Backup Management', href: '/backup', icon: Archive }, { name: 'Tasks', href: '/tasks', icon: Settings }, { name: 'Alerts', href: '/alerts', icon: Bell }, { name: 'System', href: '/system', icon: Server }, ] if (user?.roles.includes('admin')) { navigation.push({ name: 'User Management', href: '/iam', icon: Users }) } const isActive = (href: string) => { if (href === '/') { return location.pathname === '/' } return location.pathname.startsWith(href) } return (
{
// Fallback to text if image not found
const target = e.target as HTMLImageElement
target.style.display = 'none'
const fallback = target.nextElementSibling as HTMLElement
if (fallback) fallback.style.display = 'flex'
}}
/>
Dev Release V.1
{user?.username}
{user?.roles.join(', ').toUpperCase()}