Actualziacion reactiva en datos, estabilidad del formulario de creacion, cambio del nombre en los filtros
This commit is contained in:
@@ -55,7 +55,12 @@ export async function getElectronicNotices(
|
||||
const params = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
...filters
|
||||
});
|
||||
// Excluir valores undefined/null para evitar que URLSearchParams los convierta al string "undefined"
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
params.append(key, String(value));
|
||||
}
|
||||
});
|
||||
if (companyId) {
|
||||
params.append('company_id', companyId.toString());
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
</script>
|
||||
|
||||
<Dialog.Root bind:open>
|
||||
<Dialog.Content class="sm:max-w-[600px] max-h-[90vh] overflow-y-auto">
|
||||
<Dialog.Content class="sm:max-w-[600px] max-h-[90vh] overflow-y-auto" onInteractOutside={(e) => e.preventDefault()}>
|
||||
<Dialog.Header>
|
||||
<Dialog.Title>{title}</Dialog.Title>
|
||||
</Dialog.Header>
|
||||
|
||||
@@ -47,8 +47,8 @@ manejarActualizar: () => reloadData()
|
||||
);
|
||||
|
||||
// Filtros
|
||||
let searchCode = $state($page.url.searchParams.get('code') || '');
|
||||
let searchDesc = $state($page.url.searchParams.get('description') || '');
|
||||
let searchNoticeNumber = $state($page.url.searchParams.get('notice_number') || '');
|
||||
let searchPedimento = $state($page.url.searchParams.get('pedimento') || '');
|
||||
let timeout: ReturnType<typeof setTimeout>;
|
||||
|
||||
let allItems = $state<ElectronicNotice[]>(data.notices?.items || data.notices || []);
|
||||
@@ -82,15 +82,15 @@ loading = true;
|
||||
error = null;
|
||||
try {
|
||||
const response = await electronicNoticesApi.list(companyStore.activeCompany.id, {
|
||||
code: searchCode || undefined,
|
||||
description: searchDesc || undefined,
|
||||
notice_number: searchNoticeNumber || undefined,
|
||||
pedimento: searchPedimento || undefined,
|
||||
page: '1',
|
||||
page_size: pageSize.toString()
|
||||
});
|
||||
if (response.data) {
|
||||
allItems = response.data.items;
|
||||
if (response?.items) {
|
||||
allItems = response.items;
|
||||
currentPage = 1;
|
||||
totalItems = response.data.total;
|
||||
totalItems = response.total;
|
||||
}
|
||||
} catch (err) {
|
||||
error = 'Error aplicando filtros';
|
||||
@@ -99,10 +99,10 @@ loading = false;
|
||||
}
|
||||
|
||||
const url = new URL($page.url);
|
||||
if (searchCode) url.searchParams.set('code', searchCode);
|
||||
else url.searchParams.delete('code');
|
||||
if (searchDesc) url.searchParams.set('description', searchDesc);
|
||||
else url.searchParams.delete('description');
|
||||
if (searchNoticeNumber) url.searchParams.set('notice_number', searchNoticeNumber);
|
||||
else url.searchParams.delete('notice_number');
|
||||
if (searchPedimento) url.searchParams.set('pedimento', searchPedimento);
|
||||
else url.searchParams.delete('pedimento');
|
||||
history.replaceState(history.state, '', url);
|
||||
}, 500);
|
||||
}
|
||||
@@ -112,15 +112,15 @@ if (loading || !hasMore || !companyStore.activeCompany) return;
|
||||
loading = true;
|
||||
try {
|
||||
const response = await electronicNoticesApi.list(companyStore.activeCompany.id, {
|
||||
code: searchCode || undefined,
|
||||
description: searchDesc || undefined,
|
||||
notice_number: searchNoticeNumber || undefined,
|
||||
pedimento: searchPedimento || undefined,
|
||||
page: (currentPage + 1).toString(),
|
||||
page_size: pageSize.toString()
|
||||
});
|
||||
if (response.data?.items) {
|
||||
allItems = [...allItems, ...response.data.items];
|
||||
if (response?.items) {
|
||||
allItems = [...allItems, ...response.items];
|
||||
currentPage += 1;
|
||||
totalItems = response.data.total;
|
||||
totalItems = response.total;
|
||||
}
|
||||
} finally {
|
||||
loading = false;
|
||||
@@ -133,15 +133,15 @@ loading = true;
|
||||
error = null;
|
||||
try {
|
||||
const response = await electronicNoticesApi.list(companyStore.activeCompany.id, {
|
||||
code: searchCode || undefined,
|
||||
description: searchDesc || undefined,
|
||||
notice_number: searchNoticeNumber || undefined,
|
||||
pedimento: searchPedimento || undefined,
|
||||
page: '1',
|
||||
page_size: pageSize.toString()
|
||||
});
|
||||
if (response.data?.items) {
|
||||
allItems = response.data.items;
|
||||
if (response?.items) {
|
||||
allItems = response.items;
|
||||
currentPage = 1;
|
||||
totalItems = response.data.total;
|
||||
totalItems = response.total;
|
||||
}
|
||||
} finally {
|
||||
loading = false;
|
||||
@@ -165,8 +165,8 @@ const columns = $derived(createColumns(handleSuccess, { canEdit, canDelete }));
|
||||
<p class="text-muted-foreground">Catálogo de Avisos Electrónicos del sistema</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" /> Actualizar
|
||||
<Button variant="outline" size="sm" class="h-9" onclick={reloadData} disabled={loading}>
|
||||
<RefreshCw class="mr-2 h-4 w-4 {loading ? 'animate-spin' : ''}" /> Actualizar
|
||||
</Button>
|
||||
{#if !isError && canCreate}
|
||||
<Button class="h-9" onclick={() => { editingItem = null; createDialogOpen = true; }}>
|
||||
@@ -188,8 +188,8 @@ onRetry={reloadData}
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<Card.Title>Listado de Avisos Electrónicos</Card.Title>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<Input placeholder="Código" bind:value={searchCode} oninput={handleSearch} class="h-9 w-36 bg-card lg:w-44" />
|
||||
<Input placeholder="Descripción" bind:value={searchDesc} oninput={handleSearch} class="h-9 w-44 bg-card lg:w-64" />
|
||||
<Input placeholder="No. Aviso" bind:value={searchNoticeNumber} oninput={handleSearch} class="h-9 w-36 bg-card lg:w-44" />
|
||||
<Input placeholder="Pedimento" bind:value={searchPedimento} oninput={handleSearch} class="h-9 w-44 bg-card lg:w-64" />
|
||||
</div>
|
||||
</div>
|
||||
</Card.Header>
|
||||
|
||||
Reference in New Issue
Block a user