- Add tenants API endpoints (list, get, create) - Add tenant middleware override via X-View-Tenant header - Add TenantSelector dropdown component in header - Add tenant view store with persistence - Add Clientes management page - Update all navigation layouts with Clientes link for admins Admins can now: - View list of all clients - Create new clients with automatic schema setup - Switch between viewing different clients' data - See which client they are currently viewing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
121 lines
4.2 KiB
TypeScript
121 lines
4.2 KiB
TypeScript
'use client';
|
|
|
|
import Link from 'next/link';
|
|
import { usePathname } from 'next/navigation';
|
|
import { cn } from '@/lib/utils';
|
|
import {
|
|
LayoutDashboard,
|
|
FileText,
|
|
Calculator,
|
|
Settings,
|
|
LogOut,
|
|
BarChart3,
|
|
Calendar,
|
|
Bell,
|
|
Users,
|
|
Building2,
|
|
} from 'lucide-react';
|
|
import { useAuthStore } from '@/stores/auth-store';
|
|
import { logout } from '@/lib/api/auth';
|
|
import { useRouter } from 'next/navigation';
|
|
|
|
const navigation = [
|
|
{ name: 'Dashboard', href: '/dashboard', icon: LayoutDashboard },
|
|
{ name: 'CFDI', href: '/cfdi', icon: FileText },
|
|
{ name: 'Impuestos', href: '/impuestos', icon: Calculator },
|
|
{ name: 'Reportes', href: '/reportes', icon: BarChart3 },
|
|
{ name: 'Calendario', href: '/calendario', icon: Calendar },
|
|
{ name: 'Alertas', href: '/alertas', icon: Bell },
|
|
{ name: 'Usuarios', href: '/usuarios', icon: Users },
|
|
{ name: 'Config', href: '/configuracion', icon: Settings },
|
|
];
|
|
|
|
const adminNavigation = [
|
|
{ name: 'Clientes', href: '/clientes', icon: Building2 },
|
|
];
|
|
|
|
export function SidebarFloating() {
|
|
const pathname = usePathname();
|
|
const router = useRouter();
|
|
const { user, logout: clearAuth } = useAuthStore();
|
|
|
|
const allNavigation = user?.role === 'admin'
|
|
? [...navigation.slice(0, -1), ...adminNavigation, navigation[navigation.length - 1]]
|
|
: navigation;
|
|
|
|
const handleLogout = async () => {
|
|
try {
|
|
await logout();
|
|
} catch {
|
|
// Ignore errors
|
|
} finally {
|
|
clearAuth();
|
|
router.push('/login');
|
|
}
|
|
};
|
|
|
|
return (
|
|
<aside className="fixed left-4 top-4 bottom-4 z-40 w-64 rounded-2xl border border-border/50 bg-card/80 backdrop-blur-xl shadow-2xl shadow-primary/5">
|
|
<div className="flex h-full flex-col p-4">
|
|
{/* Logo */}
|
|
<div className="flex items-center gap-3 mb-6 px-2">
|
|
<div className="h-10 w-10 rounded-xl bg-gradient-to-br from-primary to-accent flex items-center justify-center shadow-lg shadow-primary/25">
|
|
<span className="text-primary-foreground font-bold text-xl">H</span>
|
|
</div>
|
|
<div>
|
|
<span className="font-bold text-lg block">Horux360</span>
|
|
<span className="text-xs text-muted-foreground">Análisis Fiscal</span>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Navigation */}
|
|
<nav className="flex-1 space-y-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-3 rounded-xl px-3 py-2.5 text-sm font-medium transition-all duration-200',
|
|
isActive
|
|
? 'bg-primary/20 text-primary shadow-sm shadow-primary/20 border border-primary/30'
|
|
: 'text-muted-foreground hover:bg-muted/50 hover:text-foreground'
|
|
)}
|
|
>
|
|
<item.icon className={cn(
|
|
'h-5 w-5 transition-transform',
|
|
isActive && 'scale-110'
|
|
)} />
|
|
{item.name}
|
|
</Link>
|
|
);
|
|
})}
|
|
</nav>
|
|
|
|
{/* User & Logout */}
|
|
<div className="mt-4 pt-4 border-t border-border/50">
|
|
<div className="flex items-center gap-3 px-2 mb-3">
|
|
<div className="h-10 w-10 rounded-xl bg-gradient-to-br from-secondary to-muted flex items-center justify-center">
|
|
<span className="text-foreground font-medium">
|
|
{user?.nombre?.charAt(0).toUpperCase()}
|
|
</span>
|
|
</div>
|
|
<div className="flex-1 min-w-0">
|
|
<p className="text-sm font-medium truncate">{user?.nombre}</p>
|
|
<p className="text-xs text-muted-foreground truncate">{user?.email}</p>
|
|
</div>
|
|
</div>
|
|
<button
|
|
onClick={handleLogout}
|
|
className="flex w-full items-center gap-3 rounded-xl px-3 py-2.5 text-sm font-medium text-muted-foreground hover:bg-destructive/20 hover:text-destructive transition-colors"
|
|
>
|
|
<LogOut className="h-5 w-5" />
|
|
Cerrar sesión
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
);
|
|
}
|