Update: nueva version Horux Despachos

This commit is contained in:
consultoria-as
2026-04-27 22:09:36 -06:00
commit 6b36db1403
614 changed files with 125926 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import { Header } from './header';
interface DashboardShellProps {
children: React.ReactNode;
title: string;
headerContent?: React.ReactNode;
}
export function DashboardShell({ children, title, headerContent }: DashboardShellProps) {
// Navigation is handled by the parent layout.tsx which respects theme settings
// DashboardShell only provides Header and content wrapper
return (
<>
<Header title={title}>{headerContent}</Header>
<main className="p-6">{children}</main>
</>
);
}

View File

@@ -0,0 +1,56 @@
'use client';
import { useThemeStore } from '@/stores/theme-store';
import { themes, type ThemeName } from '@/themes';
import { Button } from '@horux/shared-ui';
import { TenantSelector } from '@/components/tenant-selector';
import { MembershipSwitcher } from '@/components/membership-switcher';
import { ContribuyenteSelector } from '@/components/contribuyente-selector';
import { Sun, Moon, Palette } from 'lucide-react';
const themeIcons: Record<ThemeName, React.ReactNode> = {
light: <Sun className="h-4 w-4" />,
vibrant: <Palette className="h-4 w-4" />,
corporate: <Palette className="h-4 w-4" />,
dark: <Moon className="h-4 w-4" />,
};
const themeOrder: ThemeName[] = ['light', 'dark'];
interface HeaderProps {
title: string;
children?: React.ReactNode;
}
export function Header({ title, children }: HeaderProps) {
const { theme, setTheme } = useThemeStore();
const cycleTheme = () => {
const currentIndex = themeOrder.indexOf(theme);
const nextIndex = (currentIndex + 1) % themeOrder.length;
setTheme(themeOrder[nextIndex]);
};
return (
<header className="sticky top-0 z-30 flex h-16 items-center justify-between border-b bg-background/95 backdrop-blur px-6">
<div className="flex items-center gap-4 min-w-0">
<h1 className="text-xl font-semibold whitespace-nowrap">{title}</h1>
{children}
</div>
<div className="flex items-center gap-3">
<ContribuyenteSelector />
<MembershipSwitcher />
<TenantSelector />
<Button
variant="ghost"
size="icon"
onClick={cycleTheme}
title={`Tema: ${themes[theme].name}`}
>
{themeIcons[theme]}
</Button>
</div>
</header>
);
}

View File

@@ -0,0 +1,158 @@
'use client';
import Link from 'next/link';
import Image from 'next/image';
import { usePathname } from 'next/navigation';
import { cn } from '@horux/shared-ui';
import {
LayoutDashboard,
FileText,
Calculator,
Settings,
LogOut,
BarChart3,
Calendar,
Bell,
Users,
Building2,
Scale,
Send,
} from 'lucide-react';
import { useAuthStore } from '@/stores/auth-store';
import { logout } from '@/lib/api/auth';
import { useRouter } from 'next/navigation';
import { useState } from 'react';
import { hasFeature, isGlobalAdminRfc, type Plan } from '@horux/shared';
const navigation = [
{ name: 'Dashboard', href: '/dashboard', icon: LayoutDashboard, roles: ['owner', 'contador'] },
{ name: 'CFDI', href: '/cfdi', icon: FileText },
{ name: 'Impuestos', href: '/impuestos', icon: Calculator },
{ name: 'Reportes', href: '/reportes', icon: BarChart3, feature: 'reportes', roles: ['owner'] },
{ 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', 'contador'] },
{ name: 'Usuarios', href: '/usuarios', icon: Users, roles: ['owner'] },
{ name: 'Configuración', href: '/configuracion', icon: Settings, roles: ['owner'] },
] as const;
const adminNavigation = [
{ name: 'Clientes', href: '/clientes', icon: Building2 },
];
export function SidebarCompact() {
const pathname = usePathname();
const router = useRouter();
const { user, logout: clearAuth } = useAuthStore();
const [expanded, setExpanded] = useState(false);
const plan = (user?.plan || 'starter') as Plan;
const role = user?.role || 'visor';
const filteredNav = navigation.filter((item) => {
if ('feature' in item && item.feature && !hasFeature(plan, item.feature)) return false;
if ('roles' in item && item.roles && !item.roles.includes(role)) 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 (
<aside
className={cn(
'fixed left-0 top-0 z-40 h-screen border-r bg-card transition-all duration-300',
expanded ? 'w-64' : 'w-16'
)}
onMouseEnter={() => setExpanded(true)}
onMouseLeave={() => setExpanded(false)}
>
<div className="flex h-full flex-col">
{/* Logo */}
<div className="flex h-14 items-center border-b px-4">
<Link href="/dashboard" className="flex items-center gap-2">
<Image
src="/logo.jpg"
alt="Horux360"
width={32}
height={32}
className="rounded-full flex-shrink-0"
/>
<span className={cn(
'font-bold text-lg whitespace-nowrap transition-opacity duration-300',
expanded ? 'opacity-100' : 'opacity-0 w-0 overflow-hidden'
)}>
Horux360
</span>
</Link>
</div>
{/* Navigation */}
<nav className="flex-1 space-y-1 px-2 py-3">
{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 px-2 py-2 text-sm font-medium transition-colors',
isActive
? 'bg-primary text-primary-foreground'
: 'text-muted-foreground hover:bg-accent hover:text-accent-foreground'
)}
title={!expanded ? item.name : undefined}
>
<item.icon className="h-5 w-5 flex-shrink-0" />
<span className={cn(
'whitespace-nowrap transition-opacity duration-300',
expanded ? 'opacity-100' : 'opacity-0 w-0 overflow-hidden'
)}>
{item.name}
</span>
</Link>
);
})}
</nav>
{/* User & Logout */}
<div className="border-t p-2">
{expanded && (
<div className="mb-2 px-2 py-1">
<p className="text-xs font-medium truncate">{user?.nombre}</p>
<p className="text-xs text-muted-foreground truncate">{user?.email}</p>
</div>
)}
<button
onClick={handleLogout}
className={cn(
'flex w-full items-center gap-3 rounded px-2 py-2 text-sm font-medium text-muted-foreground hover:bg-destructive hover:text-destructive-foreground transition-colors'
)}
title={!expanded ? 'Cerrar sesión' : undefined}
>
<LogOut className="h-5 w-5 flex-shrink-0" />
<span className={cn(
'whitespace-nowrap transition-opacity duration-300',
expanded ? 'opacity-100' : 'opacity-0 w-0 overflow-hidden'
)}>
Cerrar sesión
</span>
</button>
</div>
</div>
</aside>
);
}

View File

@@ -0,0 +1,139 @@
'use client';
import Link from 'next/link';
import Image from 'next/image';
import { usePathname } from 'next/navigation';
import { cn } from '@horux/shared-ui';
import {
LayoutDashboard,
FileText,
Calculator,
Settings,
LogOut,
BarChart3,
Calendar,
Bell,
Users,
Building2,
Scale,
Send,
} from 'lucide-react';
import { useAuthStore } from '@/stores/auth-store';
import { logout } from '@/lib/api/auth';
import { useRouter } from 'next/navigation';
import { hasFeature, isGlobalAdminRfc, type Plan } from '@horux/shared';
const navigation = [
{ name: 'Dashboard', href: '/dashboard', icon: LayoutDashboard, roles: ['owner', 'contador'] },
{ name: 'CFDI', href: '/cfdi', icon: FileText },
{ name: 'Impuestos', href: '/impuestos', icon: Calculator },
{ name: 'Reportes', href: '/reportes', icon: BarChart3, feature: 'reportes', roles: ['owner'] },
{ 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', 'contador'] },
{ name: 'Usuarios', href: '/usuarios', icon: Users, roles: ['owner'] },
{ name: 'Config', href: '/configuracion', icon: Settings, roles: ['owner'] },
] as const;
const adminNavigation = [
{ name: 'Clientes', href: '/clientes', icon: Building2 },
];
export function SidebarFloating() {
const pathname = usePathname();
const router = useRouter();
const { user, logout: clearAuth } = useAuthStore();
const plan = (user?.plan || 'starter') as Plan;
const role = user?.role || 'visor';
const filteredNav = navigation.filter((item) => {
if ('feature' in item && item.feature && !hasFeature(plan, item.feature)) return false;
if ('roles' in item && item.roles && !item.roles.includes(role)) 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 (
<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">
<Image
src="/logo.jpg"
alt="Horux360"
width={40}
height={40}
className="rounded-full shadow-lg shadow-primary/25"
/>
<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>
);
}

View File

@@ -0,0 +1,186 @@
'use client';
import Link from 'next/link';
import Image from 'next/image';
import { usePathname } from 'next/navigation';
import { cn } from '@horux/shared-ui';
import {
LayoutDashboard,
FileText,
Calculator,
Settings,
LogOut,
BarChart3,
Calendar,
Bell,
Users,
Building2,
UserCog,
CreditCard,
Send,
Scale,
FileCheck,
FileWarning,
Shield,
Rocket,
ClipboardList,
ListChecks,
} from 'lucide-react';
import { useAuthStore } from '@/stores/auth-store';
import { logout } from '@/lib/api/auth';
import { useContribuyentes } from '@/lib/hooks/use-contribuyentes';
import { useRouter } from 'next/navigation';
import { hasFeature, isGlobalAdminRfc, isDespachoTenant, 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
roles?: string[]; // Allowed roles — hidden if user's role is not in the list
/** Visible solo si el user es owner en algún tenant (no en el activo). */
requireOwnerSomewhere?: boolean;
}
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'] },
{ name: 'Usuarios', href: '/usuarios', icon: Users, roles: ['owner', 'cfo'] },
{ name: 'Planes', href: '/configuracion/planes-despacho', icon: CreditCard, roles: ['owner', 'cfo'] },
{ name: 'Configuracion', href: '/configuracion', icon: Settings, roles: ['owner', 'cfo'] },
];
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 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 plan features + user role
const plan = (user?.plan || 'starter') as Plan;
const role = user?.role || 'visor';
const isOwnerSomewhere = (user?.tenants || []).some(t => t.isOwner);
const isDespacho = isDespachoTenant(user?.tenantRfc);
const filteredNav = navigation.filter((item) => {
if (item.feature) {
if (isDespacho) {
// Despacho tenants: all features are enabled across all plans — skip check
} else {
// Horux360: use legacy plan feature gating
if (!hasFeature(plan, item.feature)) return false;
}
}
if (item.roles && !item.roles.includes(role)) return false;
if (item.requireOwnerSomewhere && !isOwnerSomewhere) return false;
return true;
});
const { data: contribuyentes } = useContribuyentes();
const isGlobalAdmin = isGlobalAdminRfc(user?.tenantRfc, role, user?.platformRoles);
// El admin global NO necesita "Configuración inicial" — su tenant raíz
// (Horux 360) no tiene contribuyentes propios y nunca los tendrá.
const showOnboarding = (!contribuyentes || contribuyentes.length === 0) && role !== 'cliente' && !isGlobalAdmin;
const allNavigation = isGlobalAdmin
? [...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="Horux Despachos"
width={32}
height={32}
className="rounded-full"
/>
<div className="flex flex-col leading-tight">
<span className="font-bold text-xl">Horux</span>
<span className="text-xs text-muted-foreground -mt-1">Despachos</span>
</div>
</Link>
</div>
{/* Navigation */}
<nav className="flex-1 space-y-1 px-3 py-4">
{showOnboarding && (
<div className="px-3 py-2">
<Link href="/onboarding">
<div className="flex items-center gap-2 px-3 py-2 rounded-md bg-primary/10 text-primary text-sm font-medium hover:bg-primary/20 transition-colors">
<Rocket className="h-4 w-4" />
Configuración inicial
</div>
</Link>
</div>
)}
{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 — admin/TI globales no muestran nombre+email para
mantener el sidebar más limpio (ya tienen muchos items extras) */}
<div className="border-t p-4">
{!isGlobalAdmin && (
<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>
);
}

View File

@@ -0,0 +1,141 @@
'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,
} from 'lucide-react';
import { useAuthStore } from '@/stores/auth-store';
import { logout } from '@/lib/api/auth';
import { useRouter } from 'next/navigation';
import { useState } from 'react';
import { hasFeature, isGlobalAdminRfc, type Plan } from '@horux/shared';
const navigation = [
{ name: 'Dashboard', href: '/dashboard', icon: LayoutDashboard, roles: ['owner', 'contador'] },
{ name: 'CFDI', href: '/cfdi', icon: FileText },
{ name: 'Impuestos', href: '/impuestos', icon: Calculator },
{ name: 'Reportes', href: '/reportes', icon: BarChart3, feature: 'reportes', roles: ['owner'] },
{ 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', 'contador'] },
{ name: 'Usuarios', href: '/usuarios', icon: Users, roles: ['owner'] },
{ name: 'Config', href: '/configuracion', icon: Settings, roles: ['owner'] },
] as const;
const adminNavigation = [
{ name: 'Clientes', href: '/clientes', icon: Building2 },
];
export function TopNav() {
const pathname = usePathname();
const router = useRouter();
const { user, logout: clearAuth } = useAuthStore();
const [userMenuOpen, setUserMenuOpen] = useState(false);
const plan = (user?.plan || 'starter') as Plan;
const role = user?.role || 'visor';
const filteredNav = navigation.filter((item) => {
if ('feature' in item && item.feature && !hasFeature(plan, item.feature)) return false;
if ('roles' in item && item.roles && !item.roles.includes(role)) 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>
);
}