Spaces:
Runtime error
Runtime error
Greg
Claude Opus 4.7 (1M context)
feat(ta-01): responsive layout with mobile hamburger drawer
c16d5c1 Download frontend/src/components/Sidebar.tsx from Talosware/talos-access: direct link, hf CLI and curl.
- Browser
- Download file 4.54 kB
-
https://huggingface.co/spaces/Talosware/talos-access/resolve/main/frontend/src/components/Sidebar.tsx
- Command line
-
hf download hf://spaces/Talosware/talos-access/frontend/src/components/Sidebar.tsx
-
curl -L -o Sidebar.tsx https://huggingface.co/spaces/Talosware/talos-access/resolve/main/frontend/src/components/Sidebar.tsx
4.54 kB
| import { NavLink } from 'react-router-dom'; | |
| import { useAuthStore } from '../store/authStore'; | |
| import { translateRole } from '../utils/roles'; | |
| import { Users, LayoutDashboard, BookOpen, ClipboardCheck, LogOut, GraduationCap, BarChart3, Settings, CreditCard, Clock, Code2, IdCard, Heart, Calendar, Search, FileText, X } from 'lucide-react'; | |
| interface SidebarProps { | |
| mobileOpen?: boolean; | |
| onClose?: () => void; | |
| } | |
| const navItems = [ | |
| { to: '/dashboard', label: 'Dashboard', icon: LayoutDashboard, roles: ['admin', 'teacher', 'representative', 'student', 'administrativo', 'obrero'] }, | |
| { to: '/dashboard/users', label: 'Usuarios', icon: Users, roles: ['admin', 'administrativo'] }, | |
| { to: '/dashboard/subjects', label: 'Materias', icon: BookOpen, roles: ['admin'] }, | |
| { to: '/dashboard/teacher-subjects', label: 'Materias', icon: BookOpen, roles: ['teacher'] }, | |
| { to: '/dashboard/sections', label: 'Secciones', icon: GraduationCap, roles: ['admin', 'administrativo'] }, | |
| { to: '/dashboard/teacher-sections', label: 'Secciones', icon: GraduationCap, roles: ['teacher'] }, | |
| { to: '/dashboard/enrollments', label: 'Matrículas', icon: ClipboardCheck, roles: ['admin', 'administrativo'] }, | |
| { to: '/dashboard/mis-hijos', label: 'Mis Hijos', icon: Heart, roles: ['representative'] }, | |
| { to: '/dashboard/public-checkin', label: 'Mi Asistencia', icon: Clock, roles: ['admin', 'teacher', 'representative', 'student', 'administrativo', 'obrero'] }, | |
| { to: '/dashboard/teacher-attendance', label: 'Asistencia', icon: CreditCard, roles: ['teacher'] }, | |
| { to: '/dashboard/admin-attendance', label: 'Asistencia (contingencia)', icon: ClipboardCheck, roles: ['admin'] }, | |
| { to: '/dashboard/attendance', label: 'Reportes', icon: BarChart3, roles: ['admin', 'administrativo'] }, | |
| { to: '/dashboard/student-report', label: 'Rep. Estudiantes', icon: FileText, roles: ['admin', 'administrativo'] }, | |
| { to: '/dashboard/late-arrivals', label: 'Tardanzas', icon: Clock, roles: ['admin', 'administrativo', 'teacher'] }, | |
| { to: '/dashboard/audit-logs', label: 'Auditoría', icon: Search, roles: ['admin'] }, | |
| { to: '/dashboard/holidays', label: 'Calendario', icon: Calendar, roles: ['admin'] }, | |
| { to: '/dashboard/card-templates', label: 'Carnets', icon: IdCard, roles: ['admin'] }, | |
| { to: '/dashboard/settings', label: 'Configuración', icon: Settings, roles: ['admin'] }, | |
| { to: '/dashboard/developer', label: 'Desarrollador', icon: Code2, roles: ['developer'] }, | |
| ]; | |
| function hasAdminAccess(user: { role: string; permissions: string[] } | null): boolean { | |
| return user?.role === 'admin' || user?.role === 'developer' || (user?.permissions ?? []).includes('admin.full'); | |
| } | |
| export default function Sidebar({ mobileOpen = false, onClose }: SidebarProps) { | |
| const user = useAuthStore((s) => s.user); | |
| const clearAuth = useAuthStore((s) => s.clearAuth); | |
| const isAdmin = hasAdminAccess(user); | |
| const visible = navItems.filter((item) => { | |
| if (item.to === '/dashboard/public-checkin') { | |
| return isAdmin || user?.self_checkin_enabled; | |
| } | |
| // Admin-role items visible to users with admin.full permission | |
| if (item.roles.includes('admin') && !item.roles.includes('teacher')) { | |
| return isAdmin; | |
| } | |
| return item.roles.includes(user?.role ?? ''); | |
| }); | |
| return ( | |
| <aside className={`sidebar${mobileOpen ? ' sidebar-open' : ''}`}> | |
| <div className="sidebar-header"> | |
| <div className="flex flex-col"> | |
| <span className="text-xl font-bold">Talos Access</span> | |
| <span className="sidebar-role">{translateRole(user?.role)}</span> | |
| </div> | |
| {onClose && ( | |
| <button | |
| type="button" | |
| onClick={onClose} | |
| aria-label="Cerrar menú" | |
| className="md:hidden p-1.5 rounded-lg hover:bg-gray-800 text-gray-300" | |
| > | |
| <X size={18} /> | |
| </button> | |
| )} | |
| </div> | |
| <nav className="sidebar-nav"> | |
| {visible.map((item) => ( | |
| <NavLink | |
| key={item.to} | |
| to={item.to} | |
| end={item.to === '/dashboard'} | |
| onClick={onClose} | |
| className={({ isActive }) => `nav-item${isActive ? ' active' : ''}`} | |
| > | |
| <item.icon size={18} /> | |
| <span>{item.label}</span> | |
| </NavLink> | |
| ))} | |
| </nav> | |
| <div className="sidebar-footer"> | |
| <button className="nav-item w-full" onClick={clearAuth}> | |
| <LogOut size={18} /> | |
| <span>Salir</span> | |
| </button> | |
| </div> | |
| </aside> | |
| ); | |
| } | |