Files
CRM_AGENTES_CARGA/frontend/src/lib/components/sidebar/modules.ts
Ernesto Herrera 63ad2e2ecd feat(core,crm): gestión de compañías en el CRM + soporte hub_admin sin tenant
Las compañías (a76.company) se gestionan en el CRM, ligadas a un tenant del
Workspace. Cambios:

- my-companies: por MEMBRESÍA (user_tenants ∪ user_company_roles), así el hub_admin
  sin tenant en el token ve las compañías que creó/se le asignaron; para usuarios
  con tenant, autocrea una por defecto en el primer acceso.
- POST /auth/companies: da de alta una compañía bajo un tenant + asigna al usuario.
  GET /auth/assignable-tenants: tenants elegibles (hub_admin: todos; usuario: el suyo).
- security.validate_access_to_resource: si el token no trae tenant (hub_admin),
  resuelve el tenant desde la compañía activa (a76.company.tenant_id) → puede operar
  por compañía seleccionada.
- set-active: fija sso_tenant_id/pub con el tenant de la compañía (override).
- Pantalla "Compañías" (nav) para crear/listar/seleccionar.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-17 11:44:36 -06:00

127 lines
2.7 KiB
TypeScript

import {
LayoutDashboard,
Settings2,
Users,
Shield,
Briefcase,
Ship,
Receipt,
Building2,
Building,
} from '@lucide/svelte';
export type SystemContext = 'fixed_asset' | 'inventory';
export interface NavItem {
title: string;
url: string;
permission?: string;
systemContext?: SystemContext;
}
export interface NavMainItem {
title: string;
url: string;
icon: any;
isActive?: boolean;
permission?: string;
items?: NavItem[];
}
/**
* Navegación principal del dashboard.
* Agrega aquí los módulos de tu proyecto.
*/
export function getNavMain(): NavMainItem[] {
return [
{
title: 'Dashboard',
url: '/dashboard',
icon: LayoutDashboard,
},
{
title: 'CRM',
url: '/dashboard/crm',
icon: Briefcase,
items: [
{ title: 'Panel', url: '/dashboard/crm' },
{ title: 'Clientes / Prospectos', url: '/dashboard/crm/cuentas' },
{ title: 'Proveedores', url: '/dashboard/crm/proveedores' },
{ title: 'Contactos', url: '/dashboard/crm/contactos' },
{ title: 'Solicitudes', url: '/dashboard/crm/solicitudes' },
{ title: 'Cotizaciones', url: '/dashboard/crm/cotizaciones' },
{ title: 'Prospectos (embudo)', url: '/dashboard/crm/prospectos' },
{ title: 'Oportunidades', url: '/dashboard/crm/oportunidades' },
{ title: 'Actividades', url: '/dashboard/crm/actividades' },
],
},
{
title: 'Operaciones',
url: '/dashboard/ops/embarques',
icon: Ship,
items: [
{ title: 'Embarques', url: '/dashboard/ops/embarques' },
],
},
{
title: 'Facturación',
url: '/dashboard/fin/facturas',
icon: Receipt,
items: [
{ title: 'Facturas y cobranza', url: '/dashboard/fin/facturas' },
],
},
{
title: 'Compañías',
url: '/dashboard/companias',
icon: Building,
},
{
title: 'Workspace',
url: '/dashboard/workspace/organizaciones',
icon: Building2,
items: [
{ title: 'Organizaciones', url: '/dashboard/workspace/organizaciones' },
{ title: 'Usuarios (invitaciones)', url: '/dashboard/workspace/usuarios' },
],
},
{
title: 'Usuarios',
url: '/dashboard/users',
icon: Users,
},
{
title: 'Roles y permisos',
url: '/dashboard/roles',
icon: Shield,
},
{
title: 'Configuración',
url: '/dashboard/settings/general',
icon: Settings2,
},
];
}
/**
* Datos completos del sidebar (navegación + usuario fallback + proyectos).
* El usuario real se inyecta desde page.data en app-sidebar.svelte.
*/
export function getSidebarData() {
return {
navMain: getNavMain(),
projects: [] as { name: string; url: string; icon: any }[],
user: {
name: '',
email: '',
username: '',
firstName: null,
lastName: null,
displayName: '',
avatarUrl: null,
workspaceAvatarUrl: null,
legacyAvatarUrl: null,
},
};
}