feature/refactorizacion-tabla-sector

This commit is contained in:
hreyes
2026-03-17 11:21:28 -06:00
parent 20a351c475
commit fbbe4370de
32 changed files with 4167 additions and 3947 deletions

View File

@@ -2,11 +2,10 @@ import type { PageServerLoad } from './$types';
import { getAuthTokens, authenticatedFetch } from '$lib/server/api';
export const load: PageServerLoad = async ({ cookies, fetch, url, parent }) => {
// Esperar a que el layout padre valide/refresque el token
await parent();
const { accessToken } = getAuthTokens(cookies);
if (!accessToken) {
return {
error: 'No authenticated',
@@ -18,13 +17,33 @@ export const load: PageServerLoad = async ({ cookies, fetch, url, parent }) => {
}
try {
// Obtener parámetros de paginación de la URL
const page = parseInt(url.searchParams.get('page') || '1');
const pageSize = parseInt(url.searchParams.get('page_size') || '50');
// Usar authenticatedFetch para manejar automáticamente el refresh de tokens
const parentData = await parent();
const cookieCompanyId = cookies.get('active_company_id');
const companyId = cookieCompanyId
? parseInt(cookieCompanyId)
: parentData.companies?.[0]?.id;
if (!companyId) {
return {
error: 'No se encontró una compañía seleccionada',
items: [],
total: 0,
page,
page_size: pageSize
};
}
const params = new URLSearchParams({
page: page.toString(),
page_size: pageSize.toString(),
company_id: companyId.toString()
});
const response = await authenticatedFetch(
`v1/public/reference_data/sectors?page=${page}&page_size=${pageSize}`,
`v1/a76/sectors/?${params.toString()}`,
{},
cookies,
fetch
@@ -37,12 +56,12 @@ export const load: PageServerLoad = async ({ cookies, fetch, url, parent }) => {
statusText: response.statusText,
error: errorText
});
return {
error: `Error ${response.status}: ${response.statusText}`,
items: [],
total: 0,
page: page,
page,
page_size: pageSize
};
}

View File

@@ -1,6 +1,7 @@
<script lang="ts">
import { onMount } from 'svelte';
import { sectorsApi, type Sector } from '$lib/api/dashboard/reference_data/sectors';
import { companyStore } from '$lib/stores/company.svelte';
import DataTable from '$lib/components/dashboard/reference_data/sectors/data-table.svelte';
import { createColumns } from '$lib/components/dashboard/reference_data/sectors/columns.js';
import CreateEditDialog from '$lib/components/dashboard/reference_data/sectors/create-edit-dialog.svelte';
@@ -72,7 +73,12 @@
error = null;
try {
const response = await sectorsApi.list(currentPage + 1, pageSize);
const companyId = companyStore.activeCompany?.id;
if (!companyId) {
error = 'No hay empresa activa seleccionada';
return;
}
const response = await sectorsApi.list(currentPage + 1, pageSize, companyId);
if (response.error) {
console.error('📊 [Page] Error en loadMore:', response.error, 'Status:', response.status);