Merge pull request 'Refactor API calls in dashboard components to use active company ID. Updated classification, countries, and invoice types pages to ensure proper data fetching based on the selected company, enhancing user experience and data accuracy.' (#407) from fix/scroll into development
Reviewed-on: ADUANASOFT/anexo76#407
This commit is contained in:
@@ -111,7 +111,7 @@ async function loadMore() {
|
||||
if (loading || !hasMore || !companyStore.activeCompany) return;
|
||||
loading = true;
|
||||
try {
|
||||
const response = await classificationApi.list(currentPage + 1, {
|
||||
const response = await classificationApi.list(companyStore.activeCompany.id, {
|
||||
classification: searchKey || undefined,
|
||||
description: searchDesc || undefined,
|
||||
page: (currentPage + 1).toString(),
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
import { userHasCountriesRefAction } from '$lib/permissions/reference-data/countries-ref-permissions';
|
||||
import { getAccessTokenFromDocument } from '$lib/access-token-cookie-browser';
|
||||
import ErrorState from '$lib/components/dashboard/common/error-state.svelte';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
|
||||
// Los datos iniciales vienen del servidor
|
||||
let { data }: { data: PageData } = $props();
|
||||
@@ -78,12 +79,19 @@
|
||||
|
||||
function handleSearch() {
|
||||
if (!browser) return;
|
||||
if (!companyStore.activeCompany) return;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(async () => {
|
||||
if (!companyStore.activeCompany) return;
|
||||
loading = true;
|
||||
error = null;
|
||||
try {
|
||||
const response = await countriesApi.list(1, pageSize, searchQuery as any);
|
||||
const response = await countriesApi.list(
|
||||
companyStore.activeCompany.id,
|
||||
1,
|
||||
pageSize,
|
||||
searchQuery
|
||||
);
|
||||
if (!response.error && response.data) {
|
||||
allItems = response.data.items;
|
||||
currentPage = 1;
|
||||
@@ -104,13 +112,18 @@
|
||||
}
|
||||
|
||||
async function loadMore() {
|
||||
if (loading || !hasMore) return;
|
||||
if (loading || !hasMore || !companyStore.activeCompany) return;
|
||||
|
||||
loading = true;
|
||||
error = null;
|
||||
|
||||
try {
|
||||
const response = await countriesApi.list(currentPage + 1, pageSize, searchQuery as any);
|
||||
try {
|
||||
const response = await countriesApi.list(
|
||||
companyStore.activeCompany.id,
|
||||
currentPage + 1,
|
||||
pageSize,
|
||||
searchQuery
|
||||
);
|
||||
if (response.error) {
|
||||
console.error('📊 [Page] Error en loadMore:', response.error, 'Status:', response.status);
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
loading = true;
|
||||
error = null;
|
||||
try {
|
||||
const response = await invoiceTypesApi.list(1, pageSize, searchQuery);
|
||||
const response = await invoiceTypesApi.list(1, pageSize, undefined, searchQuery);
|
||||
if (!response.error && response.data) {
|
||||
allItems = response.data.items;
|
||||
currentPage = 1;
|
||||
@@ -81,7 +81,7 @@
|
||||
loading = true;
|
||||
error = null;
|
||||
try {
|
||||
const response = await invoiceTypesApi.list(currentPage + 1, pageSize, searchQuery);
|
||||
const response = await invoiceTypesApi.list(currentPage + 1, pageSize, undefined, searchQuery);
|
||||
if (response.error) {
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
error = 'Sesión expirada. Recargando página...';
|
||||
|
||||
Reference in New Issue
Block a user