diff --git a/frontend/src/routes/dashboard/customs_brokers/+page.svelte b/frontend/src/routes/dashboard/customs_brokers/+page.svelte index baa5e120..b926ce5f 100644 --- a/frontend/src/routes/dashboard/customs_brokers/+page.svelte +++ b/frontend/src/routes/dashboard/customs_brokers/+page.svelte @@ -75,10 +75,14 @@ const canDeleteBroker = $derived(canDeleteCustomsBrokers($currentUser)); // --- Customs Sections State --- + // Catálogo de solo lectura: se alimenta del mismo endpoint que + // /dashboard/reference_data/customs_sections (mismo origen de datos). let sections = $state([]); let loadingSections = $state(false); let totalSections = $state(0); let sectionsPage = $state(1); + let sectionsSearch = $state(''); + let sectionsSearchTimeout: ReturnType; let hasMoreSections = $derived(sections.length < totalSections); // --- Lifecycle --- @@ -160,12 +164,14 @@ // Customs Sections Actions async function loadSections() { - // Simple loading logic reusing existing API - // Assuming we load all or paginate - trying to match existing page logic if (loadingSections) return; + // El store puede no estar hidratado al montar (su init corre en el onMount + // del layout padre); usamos el companyId resuelto por SSR como respaldo. + const companyId = companyStore.activeCompany?.id ?? data.currentCompanyId; + if (!companyId) return; loadingSections = true; try { - const response = await customsSectionsApi.list(sectionsPage, 50); + const response = await customsSectionsApi.list(companyId, sectionsPage, 50, sectionsSearch); if (response.data?.items) { sections = sectionsPage === 1 ? response.data.items : [...sections, ...response.data.items]; totalSections = response.data.total; @@ -183,6 +189,15 @@ await loadSections(); } + // Búsqueda server-side con debounce; resetea a la primera página + function handleSectionsSearch() { + clearTimeout(sectionsSearchTimeout); + sectionsSearchTimeout = setTimeout(() => { + sectionsPage = 1; + loadSections(); + }, 500); + } + // Shortcuts Integration useShortcuts( 'Customs Brokers List', @@ -196,11 +211,8 @@ return; } goto('/dashboard/customs_brokers/edit/new'); - } else { - // For Customs Sections, we might need a dialog. - // Since we are "not modifying logic", we'll just show a toast or Placeholder TODO - toast.info('Crear Sección Aduanal: Implementación pendiente de diálogo'); } + // Secciones Aduanales es un catálogo de solo lectura: sin acción de crear. }, recargar: () => { if (activeTab === 'brokers') loadItems(); @@ -212,10 +224,14 @@ }) ); - const sectionsColumns = createSectionColumns(() => { - sectionsPage = 1; - loadSections(); - }); + // Solo lectura: se ocultan las acciones de Editar/Eliminar en el menú de cada fila. + const sectionsColumns = createSectionColumns( + () => { + sectionsPage = 1; + loadSections(); + }, + { canEdit: false, canDelete: false } + ); const brokerColumns = createBrokerColumns(handleActionSuccess); @@ -432,18 +448,37 @@ - - - - + + + +
+ Listado de Secciones Aduanales + +
+
+ +
+ +
+
+ Mostrando {sections.length} de {totalSections} registros +
@@ -482,12 +517,8 @@ Borrar {/if} - {:else} - {/if} +