Arreglo de equivalencias
This commit is contained in:
@@ -16,11 +16,13 @@
|
||||
let {
|
||||
open = $bindable(false),
|
||||
item = null,
|
||||
equivalency_id = null,
|
||||
defaultOriginalField = null,
|
||||
onSuccess
|
||||
}: {
|
||||
open: boolean;
|
||||
item?: EquivalencyItem | null;
|
||||
equivalency_id?: number | null;
|
||||
defaultOriginalField?: string | null;
|
||||
onSuccess?: () => void;
|
||||
} = $props();
|
||||
@@ -82,7 +84,8 @@
|
||||
|
||||
const dataToSend = {
|
||||
original_field: formData.original_field.trim(),
|
||||
external_field: formData.external_field.trim()
|
||||
external_field: formData.external_field.trim(),
|
||||
equivalency_id: equivalency_id
|
||||
};
|
||||
|
||||
if (isEdit && item) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import * as Table from '$lib/components/ui/table';
|
||||
import { companyStore } from '$lib/stores/company.svelte';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { friendlyApiErrorParts } from '$lib/api';
|
||||
import { Check } from 'lucide-svelte';
|
||||
import type {
|
||||
Equivalency,
|
||||
@@ -68,7 +69,17 @@
|
||||
loading = true;
|
||||
error = null;
|
||||
try {
|
||||
const resp = await getEquivalencyItems(1, 2000, companyId);
|
||||
const eq = getEffectiveEquivalency();
|
||||
if (!eq && mode === 'create') {
|
||||
items = [];
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const filters: Record<string, any> = {};
|
||||
if (eq) filters.equivalency_id = eq.id;
|
||||
|
||||
const resp = await getEquivalencyItems(1, 2000, companyId, filters);
|
||||
if (resp.error) throw new Error(resp.error);
|
||||
items = resp.data.items || [];
|
||||
} catch (e) {
|
||||
@@ -144,7 +155,8 @@
|
||||
companyId
|
||||
);
|
||||
if (created.error || !created.data) {
|
||||
toast.error(created.error || 'Error al guardar');
|
||||
const { title, description } = friendlyApiErrorParts(created);
|
||||
toast.error(title, { description });
|
||||
return;
|
||||
}
|
||||
savedEquivalency = created.data;
|
||||
@@ -248,7 +260,6 @@
|
||||
function handleInputsSuccess() {
|
||||
inputsOpen = false;
|
||||
reloadItems();
|
||||
onSuccess?.();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -378,6 +389,7 @@
|
||||
<EquivalencyItemCreateEditDialog
|
||||
bind:open={inputsOpen}
|
||||
item={inputsItem}
|
||||
equivalency_id={getEffectiveEquivalency()?.id ?? null}
|
||||
defaultOriginalField={inputsItem ? null : null}
|
||||
onSuccess={handleInputsSuccess}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user