- Sidebars/topnav: agrega 'auxiliar' y 'cliente' a la opción Configuracion - /configuracion/page.tsx: auxiliar y cliente solo ven Información de Usuario, Información de Empresa y Seguridad (cambio de contraseña). Todo lo demás (FIEL, Obligaciones, Notificaciones, Facturación, CSD) queda restringido a owner/cfo/supervisor
172 lines
6.5 KiB
TypeScript
172 lines
6.5 KiB
TypeScript
'use client';
|
|
|
|
import Link from 'next/link';
|
|
import { usePathname } from 'next/navigation';
|
|
import { cn } from '@horux/shared-ui';
|
|
import {
|
|
LayoutDashboard,
|
|
FileText,
|
|
Calculator,
|
|
Settings,
|
|
LogOut,
|
|
BarChart3,
|
|
Calendar,
|
|
Bell,
|
|
Users,
|
|
ChevronDown,
|
|
Building2,
|
|
Scale,
|
|
Send,
|
|
ListChecks,
|
|
FileCheck,
|
|
ClipboardList,
|
|
CreditCard,
|
|
Gift,
|
|
CheckSquare2,
|
|
UserCog,
|
|
Shield,
|
|
FileWarning,
|
|
Receipt,
|
|
} from 'lucide-react';
|
|
import { useAuthStore } from '@/stores/auth-store';
|
|
import { logout } from '@/lib/api/auth';
|
|
import { useNavGate } from '@/lib/hooks/use-nav-gate';
|
|
import { useRouter } from 'next/navigation';
|
|
import { useState } from 'react';
|
|
import { hasDespachoFeature, isGlobalAdminRfc, type DespachoPlan } from '@horux/shared';
|
|
|
|
interface NavItem {
|
|
name: string;
|
|
href: string;
|
|
icon: any;
|
|
feature?: string;
|
|
roles?: string[];
|
|
}
|
|
|
|
const navigation: NavItem[] = [
|
|
{ name: 'Despacho', href: '/despachos', icon: ListChecks, roles: ['owner', 'cfo', 'contador', 'auxiliar', 'supervisor'] },
|
|
{ name: 'Dashboard', href: '/dashboard', icon: LayoutDashboard, roles: ['owner', 'cfo', 'contador', 'auxiliar', 'supervisor', 'cliente'] },
|
|
{ name: 'CFDI', href: '/cfdi', icon: FileText },
|
|
{ name: 'Impuestos', href: '/impuestos', icon: Calculator },
|
|
{ name: 'Reportes', href: '/reportes', icon: BarChart3, feature: 'reportes', roles: ['owner', 'cfo', 'supervisor', 'cliente'] },
|
|
{ name: 'Conciliacion', href: '/conciliacion', icon: Scale, feature: 'conciliacion' },
|
|
{ name: 'Calendario', href: '/calendario', icon: Calendar, feature: 'calendario' },
|
|
{ name: 'Alertas', href: '/alertas', icon: Bell, feature: 'alertas' },
|
|
{ name: 'Facturación', href: '/facturacion', icon: Send, roles: ['owner', 'cfo', 'contador', 'auxiliar', 'supervisor'] },
|
|
{ name: 'Documentos', href: '/documentos', icon: FileCheck, feature: 'documentos' },
|
|
{ name: 'Carteras', href: '/carteras', icon: ClipboardList, roles: ['supervisor', 'auxiliar'] },
|
|
{ name: 'Contribuyentes', href: '/contribuyentes', icon: Building2, roles: ['owner', 'cfo', 'supervisor', 'contador', 'auxiliar'] },
|
|
{ name: 'Usuarios', href: '/usuarios', icon: Users, roles: ['owner', 'cfo'] },
|
|
{ name: 'Tareas', href: '/tareas', icon: CheckSquare2, roles: ['owner', 'cfo', 'contador', 'auxiliar', 'supervisor'] },
|
|
{ name: 'Planes', href: '/configuracion/planes-despacho', icon: CreditCard, roles: ['owner', 'cfo'] },
|
|
{ name: 'Configuracion', href: '/configuracion', icon: Settings, roles: ['owner', 'cfo', 'supervisor', 'auxiliar', 'cliente'] },
|
|
];
|
|
|
|
const adminNavigation: NavItem[] = [
|
|
{ name: 'Clientes', href: '/clientes', icon: Building2 },
|
|
{ name: 'Admin Usuarios', href: '/admin/usuarios', icon: UserCog },
|
|
{ name: 'Staff', href: '/admin/staff', icon: Shield },
|
|
{ name: 'Audit Log', href: '/admin/audit-log', icon: FileWarning },
|
|
];
|
|
|
|
export function TopNav() {
|
|
const pathname = usePathname();
|
|
const router = useRouter();
|
|
const { user, logout: clearAuth } = useAuthStore();
|
|
const [userMenuOpen, setUserMenuOpen] = useState(false);
|
|
|
|
const plan = (user?.plan || 'trial') as DespachoPlan;
|
|
const role = user?.role || 'visor';
|
|
const navGate = useNavGate();
|
|
const filteredNav = navigation.filter((item) => {
|
|
if ('feature' in item && item.feature && !hasDespachoFeature(plan, item.feature)) return false;
|
|
if ('roles' in item && item.roles && !item.roles.includes(role)) return false;
|
|
if (!navGate.isAllowed(item.href)) return false;
|
|
return true;
|
|
});
|
|
|
|
const isGlobalAdmin = isGlobalAdminRfc(user?.tenantRfc, role, user?.platformRoles);
|
|
const allNavigation = isGlobalAdmin
|
|
? [...filteredNav.slice(0, -1), ...adminNavigation, filteredNav[filteredNav.length - 1]]
|
|
: filteredNav;
|
|
|
|
const handleLogout = async () => {
|
|
try {
|
|
await logout();
|
|
} catch {
|
|
// Ignore errors
|
|
} finally {
|
|
clearAuth();
|
|
router.push('/login');
|
|
}
|
|
};
|
|
|
|
return (
|
|
<header className="fixed top-0 left-0 right-0 z-40 h-16 border-b bg-card">
|
|
<div className="flex h-full items-center px-6">
|
|
{/* Logo */}
|
|
<Link href="/dashboard" className="flex items-center gap-2 mr-8">
|
|
<div className="h-8 w-8 rounded-lg bg-primary flex items-center justify-center">
|
|
<span className="text-primary-foreground font-bold text-lg">H</span>
|
|
</div>
|
|
<span className="font-bold text-xl">Horux360</span>
|
|
</Link>
|
|
|
|
{/* Navigation */}
|
|
<nav className="flex-1 flex items-center gap-1">
|
|
{allNavigation.map((item) => {
|
|
const isActive = pathname === item.href || pathname.startsWith(`${item.href}/`);
|
|
return (
|
|
<Link
|
|
key={item.name}
|
|
href={item.href}
|
|
className={cn(
|
|
'flex items-center gap-2 rounded-lg px-3 py-2 text-sm font-medium transition-colors',
|
|
isActive
|
|
? 'bg-primary text-primary-foreground'
|
|
: 'text-muted-foreground hover:bg-accent hover:text-accent-foreground'
|
|
)}
|
|
>
|
|
<item.icon className="h-4 w-4" />
|
|
<span className="hidden lg:inline">{item.name}</span>
|
|
</Link>
|
|
);
|
|
})}
|
|
</nav>
|
|
|
|
{/* User Menu */}
|
|
<div className="relative">
|
|
<button
|
|
onClick={() => setUserMenuOpen(!userMenuOpen)}
|
|
className="flex items-center gap-2 rounded-lg px-3 py-2 text-sm font-medium hover:bg-accent transition-colors"
|
|
>
|
|
<div className="h-8 w-8 rounded-full bg-primary/10 flex items-center justify-center">
|
|
<span className="text-primary font-medium text-sm">
|
|
{user?.nombre?.charAt(0).toUpperCase()}
|
|
</span>
|
|
</div>
|
|
<span className="hidden md:inline">{user?.nombre}</span>
|
|
<ChevronDown className="h-4 w-4" />
|
|
</button>
|
|
|
|
{userMenuOpen && (
|
|
<div className="absolute right-0 top-full mt-2 w-48 rounded-lg border bg-card shadow-lg">
|
|
<div className="p-3 border-b">
|
|
<p className="text-sm font-medium">{user?.nombre}</p>
|
|
<p className="text-xs text-muted-foreground">{user?.email}</p>
|
|
</div>
|
|
<button
|
|
onClick={handleLogout}
|
|
className="flex w-full items-center gap-2 px-3 py-2 text-sm text-destructive hover:bg-destructive/10 transition-colors"
|
|
>
|
|
<LogOut className="h-4 w-4" />
|
|
Cerrar sesión
|
|
</button>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</header>
|
|
);
|
|
}
|