import { useEffect, useState } from 'react' import { NavLink, Navigate, Route, Routes, useLocation } from 'react-router-dom' import { KeyRound, LogOut, Menu, Moon, Router, ScrollText, Sun, UserCog, Users as UsersIcon, Wifi, X, } from 'lucide-react' import { useAuth } from '@/auth/auth' import { useTheme } from '@/lib/theme' import { Login } from '@/pages/Login' import { Clients } from '@/pages/Clients' import { Devices } from '@/pages/Devices' import { Vlans } from '@/pages/Vlans' import { Users } from '@/pages/Users' import { ApiKeys } from '@/pages/ApiKeys' import { Logs } from '@/pages/Logs' import { ChangePassword } from '@/pages/ChangePassword' import { Button } from '@/components/ui/button' import { cn } from '@/lib/utils' function ThemeToggle() { const { theme, toggle } = useTheme() return ( ) } type NavItem = { to: string; label: string; icon: typeof Wifi } const linkClass = ({ isActive }: { isActive: boolean }) => cn( 'flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium transition-colors', isActive ? 'bg-primary text-primary-foreground' : 'text-muted-foreground hover:bg-accent', ) function SidebarContent({ username, isAdmin, onNavigate, }: { username: string isAdmin: boolean onNavigate?: () => void }) { const { logout } = useAuth() const items: NavItem[] = [ { to: '/clients', label: 'Clients', icon: UsersIcon }, { to: '/devices', label: 'Devices', icon: Router }, { to: '/vlans', label: 'VLANs', icon: Wifi }, ] const adminItems: NavItem[] = [ { to: '/users', label: 'Users', icon: UserCog }, { to: '/apikeys', label: 'API Keys', icon: KeyRound }, { to: '/logs', label: 'Activity Log', icon: ScrollText }, ] const renderItem = ({ to, label, icon: Icon }: NavItem) => ( {label} ) return (
RADIUS Admin
{username}
) } function Shell({ username, isAdmin, children, }: { username: string isAdmin: boolean children: React.ReactNode }) { const [open, setOpen] = useState(false) const location = useLocation() // Close the mobile drawer whenever the route changes. useEffect(() => { setOpen(false) }, [location.pathname]) return (
{/* Desktop sidebar */} {/* Mobile drawer */} {open && (
setOpen(false)} aria-hidden="true" />
)} {/* Mobile top bar */}
RADIUS Admin
{/* Desktop top-right theme toggle */}
{children}
) } export default function App() { const { user } = useAuth() if (!user) return if (user.must_change_password) return const admin = user.is_admin return ( } /> } /> } /> } /> : } /> : } /> : } /> } /> ) }