fix: solución de bloqueos y estandarización de permisos
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Loader2, Search } from 'lucide-svelte';
|
||||
import { countriesApi } from '$lib/api/dashboard/reference_data/countries';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
import { toast } from 'svelte-sonner';
|
||||
|
||||
let {
|
||||
open = $bindable(),
|
||||
@@ -22,27 +25,27 @@
|
||||
loading = true;
|
||||
error = '';
|
||||
try {
|
||||
const response = await fetch('/api-sveltekit/countries', {
|
||||
credentials: 'include'
|
||||
});
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (Array.isArray(data)) {
|
||||
countries = data;
|
||||
} else if (data.items && Array.isArray(data.items)) {
|
||||
countries = data.items;
|
||||
} else {
|
||||
console.error('Unexpected data format:', data);
|
||||
countries = [];
|
||||
}
|
||||
filteredCountries = countries;
|
||||
} else {
|
||||
error = `Error: ${response.status} - ${response.statusText}`;
|
||||
console.error('Error response:', await response.text());
|
||||
const companyId = companyStore.activeCompany?.id;
|
||||
if (!companyId) {
|
||||
error = 'No hay una empresa activa seleccionada';
|
||||
return;
|
||||
}
|
||||
|
||||
// Para este diálogo, cargamos una cantidad grande o implementamos paginación si fuera necesario
|
||||
// Por ahora seguimos el patrón original de cargar "todos" (limite 100 en backend)
|
||||
const response = await countriesApi.list(companyId, 1, 100);
|
||||
|
||||
if (response.data) {
|
||||
countries = response.data.items || [];
|
||||
filteredCountries = countries;
|
||||
} else if (response.error) {
|
||||
error = `Error: ${response.error}`;
|
||||
toast.error(error);
|
||||
}
|
||||
} catch (err) {
|
||||
error = 'Error loading countries';
|
||||
console.error('Error loading countries:', err);
|
||||
toast.error(error);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user