diff --git a/src/components/DashboardShell.tsx b/src/components/DashboardShell.tsx index ecea25b..2332140 100644 --- a/src/components/DashboardShell.tsx +++ b/src/components/DashboardShell.tsx @@ -24,6 +24,7 @@ import { Images, History, Plug, + ChevronDown, } from 'lucide-react'; import SidebarTenantSwitcher from '@/components/SidebarTenantSwitcher'; import type { DashboardModuleId } from '@/lib/tenant-modules'; @@ -145,19 +146,43 @@ function isActive(pathname: string, href: string): boolean { function NavLink({ item, onNavigate, + hasSubItems, + isOpen, + onToggle, }: { item: NavItem | (Omit & { moduleId?: string }); onNavigate?: () => void; + hasSubItems?: boolean; + isOpen?: boolean; + onToggle?: () => void; }) { const pathname = usePathname(); const active = isActive(pathname, item.href); const Icon = item.icon; + + const handleClick = (e: React.MouseEvent) => { + if (hasSubItems && onToggle) { + if (active) { + // Si ya está en esta página, hacer clic en la sección pliega/despliega sin recargar + e.preventDefault(); + onToggle(); + return; + } else if (!isOpen) { + // Al entrar a la sección, asegurar que se abre + onToggle(); + } + } + if (onNavigate) { + onNavigate(); + } + }; + return ( ) : null} - - {item.label} +
+ + {item.label} +
+ {hasSubItems ? ( + { + e.preventDefault(); + e.stopPropagation(); + onToggle?.(); + }} + onKeyDown={(e) => { + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault(); + e.stopPropagation(); + onToggle?.(); + } + }} + className="p-1 rounded hover:bg-white/10 text-mist-400 hover:text-white transition-colors shrink-0" + aria-label={isOpen ? 'Ocultar páginas' : 'Mostrar páginas'} + > + + + ) : null} ); } @@ -204,6 +257,33 @@ export default function DashboardShell({ const pathname = usePathname(); const showDateHeader = shouldShowDateHeader(pathname); + const isSocialRoute = + pathname === '/dashboard/social' || + pathname === '/dashboard/calendario' || + pathname === '/dashboard/creatives'; + + const isAgenciaRoute = + pathname === '/dashboard/agencia' || + (pathname !== null && pathname.startsWith('/dashboard/agencia/')); + + const [expandedSections, setExpandedSections] = useState>({}); + + const isSocialOpen = expandedSections['social'] ?? isSocialRoute; + const isAgenciaOpen = expandedSections['agencia'] ?? isAgenciaRoute; + + const toggleSection = (key: 'social' | 'agencia') => { + setExpandedSections((prev) => { + const current = + key === 'social' + ? (prev['social'] ?? isSocialRoute) + : (prev['agencia'] ?? isAgenciaRoute); + return { + ...prev, + [key]: !current, + }; + }); + }; + const moduleOn = (id: DashboardModuleId) => { if (isAgency) return true; if (!enabledModules) return true; @@ -246,8 +326,14 @@ export default function DashboardShell({ const underSocial = item.moduleId === 'social'; return (
- - {underSocial ? ( + toggleSection('social')} + onNavigate={close} + /> + {underSocial && isSocialOpen ? ( <> {moduleOn('calendario') ? ( toggleSection('agencia')} onNavigate={close} /> - - - Panel de control · clientes y conexiones - + {isAgenciaOpen ? ( + + + Panel de control · clientes y conexiones + + ) : null}