- Add plan field to UserInfo shared type - Subscription API client and React Query hooks - Client subscription page with status + payment history - Sidebar navigation filtered by tenant plan features - Subscription link added to navigation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
133 lines
4.2 KiB
TypeScript
133 lines
4.2 KiB
TypeScript
'use client';
|
|
|
|
import Link from 'next/link';
|
|
import Image from 'next/image';
|
|
import { usePathname } from 'next/navigation';
|
|
import { cn } from '@/lib/utils';
|
|
import {
|
|
LayoutDashboard,
|
|
FileText,
|
|
Calculator,
|
|
Settings,
|
|
LogOut,
|
|
BarChart3,
|
|
Calendar,
|
|
Bell,
|
|
Users,
|
|
Building2,
|
|
UserCog,
|
|
CreditCard,
|
|
} from 'lucide-react';
|
|
import { useAuthStore } from '@/stores/auth-store';
|
|
import { logout } from '@/lib/api/auth';
|
|
import { useRouter } from 'next/navigation';
|
|
import { hasFeature, type Plan } from '@horux/shared';
|
|
|
|
interface NavItem {
|
|
name: string;
|
|
href: string;
|
|
icon: typeof LayoutDashboard;
|
|
feature?: string; // Required plan feature — hidden if tenant's plan lacks it
|
|
}
|
|
|
|
const navigation: NavItem[] = [
|
|
{ name: 'Dashboard', href: '/dashboard', icon: LayoutDashboard },
|
|
{ name: 'CFDI', href: '/cfdi', icon: FileText },
|
|
{ name: 'Impuestos', href: '/impuestos', icon: Calculator },
|
|
{ name: 'Reportes', href: '/reportes', icon: BarChart3, feature: 'reportes' },
|
|
{ name: 'Calendario', href: '/calendario', icon: Calendar, feature: 'calendario' },
|
|
{ name: 'Alertas', href: '/alertas', icon: Bell, feature: 'alertas' },
|
|
{ name: 'Usuarios', href: '/usuarios', icon: Users },
|
|
{ name: 'Suscripción', href: '/configuracion/suscripcion', icon: CreditCard },
|
|
{ name: 'Configuracion', href: '/configuracion', icon: Settings },
|
|
];
|
|
|
|
const adminNavigation: NavItem[] = [
|
|
{ name: 'Clientes', href: '/clientes', icon: Building2 },
|
|
{ name: 'Admin Usuarios', href: '/admin/usuarios', icon: UserCog },
|
|
];
|
|
|
|
export function Sidebar() {
|
|
const pathname = usePathname();
|
|
const router = useRouter();
|
|
const { user, logout: clearAuth } = useAuthStore();
|
|
|
|
const handleLogout = async () => {
|
|
try {
|
|
await logout();
|
|
} catch {
|
|
// Ignore errors
|
|
} finally {
|
|
clearAuth();
|
|
router.push('/login');
|
|
}
|
|
};
|
|
|
|
// Filter navigation based on tenant plan features
|
|
const plan = (user?.plan || 'starter') as Plan;
|
|
const filteredNav = navigation.filter(
|
|
(item) => !item.feature || hasFeature(plan, item.feature)
|
|
);
|
|
|
|
const allNavigation = user?.role === 'admin'
|
|
? [...filteredNav.slice(0, -1), ...adminNavigation, filteredNav[filteredNav.length - 1]]
|
|
: filteredNav;
|
|
|
|
return (
|
|
<aside className="fixed left-0 top-0 z-40 h-screen w-64 border-r bg-card">
|
|
<div className="flex h-full flex-col">
|
|
{/* Logo */}
|
|
<div className="flex h-16 items-center border-b px-6">
|
|
<Link href="/dashboard" className="flex items-center gap-2">
|
|
<Image
|
|
src="/logo.jpg"
|
|
alt="Horux360"
|
|
width={32}
|
|
height={32}
|
|
className="rounded-full"
|
|
/>
|
|
<span className="font-bold text-xl">Horux360</span>
|
|
</Link>
|
|
</div>
|
|
|
|
{/* Navigation */}
|
|
<nav className="flex-1 space-y-1 px-3 py-4">
|
|
{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-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-5 w-5" />
|
|
{item.name}
|
|
</Link>
|
|
);
|
|
})}
|
|
</nav>
|
|
|
|
{/* User & Logout */}
|
|
<div className="border-t p-4">
|
|
<div className="mb-3 px-3">
|
|
<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-3 rounded-lg px-3 py-2 text-sm font-medium text-muted-foreground hover:bg-destructive hover:text-destructive-foreground transition-colors"
|
|
>
|
|
<LogOut className="h-5 w-5" />
|
|
Cerrar sesion
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
);
|
|
}
|