fix/INP-filtros-y-modal
This commit is contained in:
@@ -34,11 +34,22 @@ export async function getINPCs(
|
||||
companyId: number,
|
||||
filters: Record<string, any> = {}
|
||||
): Promise<ApiResponse<INPCListResponse>> {
|
||||
const cleanFilters = Object.fromEntries(
|
||||
Object.entries(filters).filter(([, value]) => {
|
||||
if (value === undefined || value === null) return false;
|
||||
if (typeof value === 'string') {
|
||||
const trimmed = value.trim();
|
||||
return trimmed !== '' && trimmed.toLowerCase() !== 'undefined';
|
||||
}
|
||||
return true;
|
||||
})
|
||||
);
|
||||
|
||||
const params = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
company_id: companyId.toString(),
|
||||
...filters
|
||||
...cleanFilters
|
||||
});
|
||||
|
||||
return await api.get(`/v1/a76/inpc/?${params.toString()}`);
|
||||
|
||||
@@ -86,7 +86,10 @@
|
||||
</script>
|
||||
|
||||
<Dialog.Root bind:open>
|
||||
<Dialog.Content class="sm:max-w-[500px]">
|
||||
<Dialog.Content
|
||||
class="sm:max-w-[500px]"
|
||||
onInteractOutside={(e) => e.preventDefault()}
|
||||
>
|
||||
<Dialog.Header>
|
||||
<Dialog.Title>{title}</Dialog.Title>
|
||||
</Dialog.Header>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import * as Card from '$lib/components/ui/card';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Pencil, Plus, Trash2, RefreshCw } from 'lucide-svelte';
|
||||
import { Pencil, Plus, Trash2 } from 'lucide-svelte';
|
||||
import { useShortcuts } from '$lib/hooks/use-shortcuts';
|
||||
import { obtenerAtajosListaINPC } from '$lib/config/shortcuts/dashboard/general_catalogs/inpc/list';
|
||||
import { inpcApi, type INPC } from '$lib/api/dashboard/a76/general_catalogs/inpc';
|
||||
@@ -88,10 +88,11 @@
|
||||
page: '1',
|
||||
page_size: pageSize.toString()
|
||||
});
|
||||
if (response.data) {
|
||||
allItems = response.data.items;
|
||||
currentPage = 1;
|
||||
totalItems = response.data.total;
|
||||
const payload = (response as any).items ? response : (response as any).data;
|
||||
if (payload?.items) {
|
||||
allItems = payload.items;
|
||||
currentPage = payload.page || 1;
|
||||
totalItems = payload.total;
|
||||
}
|
||||
} catch (err) {
|
||||
error = 'Error aplicando filtros';
|
||||
@@ -118,11 +119,14 @@
|
||||
page: (currentPage + 1).toString(),
|
||||
page_size: pageSize.toString()
|
||||
});
|
||||
if (response.data?.items) {
|
||||
allItems = [...allItems, ...response.data.items];
|
||||
currentPage += 1;
|
||||
totalItems = response.data.total;
|
||||
const payload = (response as any).items ? response : (response as any).data;
|
||||
if (payload?.items) {
|
||||
allItems = [...allItems, ...payload.items];
|
||||
currentPage = payload.page || currentPage + 1;
|
||||
totalItems = payload.total;
|
||||
}
|
||||
} catch (err) {
|
||||
error = 'Error cargando mas datos';
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
@@ -139,11 +143,14 @@
|
||||
page: '1',
|
||||
page_size: pageSize.toString()
|
||||
});
|
||||
if (response.data) {
|
||||
allItems = response.data.items;
|
||||
currentPage = 1;
|
||||
totalItems = response.data.total;
|
||||
const payload = (response as any).items ? response : (response as any).data;
|
||||
if (payload?.items) {
|
||||
allItems = payload.items;
|
||||
currentPage = payload.page || 1;
|
||||
totalItems = payload.total;
|
||||
}
|
||||
} catch (err) {
|
||||
error = 'Error al recargar datos';
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
@@ -168,9 +175,6 @@
|
||||
<p class="text-muted-foreground">{m['common.sub_inpc']()}</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<Button variant="outline" size="sm" class="h-9" onclick={reloadData}>
|
||||
<RefreshCw class="mr-2 h-4 w-4" /> {m['common.btn_refresh']()}
|
||||
</Button>
|
||||
{#if !isError && canCreate}
|
||||
<Button
|
||||
class="h-9"
|
||||
|
||||
Reference in New Issue
Block a user