diff --git a/frontend/src/routes/dashboard/invoices/edit/[id]/+page.svelte b/frontend/src/routes/dashboard/invoices/edit/[id]/+page.svelte index e2f17af5..97ea106a 100644 --- a/frontend/src/routes/dashboard/invoices/edit/[id]/+page.svelte +++ b/frontend/src/routes/dashboard/invoices/edit/[id]/+page.svelte @@ -153,7 +153,7 @@ const othersSkeleton = { comments_status: '', transport_mode: 'TRUCK', - is_mixed: null, + is_mixed: false, print_stamp: false, rule_3121_parties_ii: false, related_doc_id: null, @@ -165,7 +165,15 @@ operation_num: '', adendas: '', observations_vu: '', - certified_number: '' + certified_number: '', + // Export fields + bill_number: '', + guide_number: '', + shipment_number: '', + option_iv18: '', + delivered_status: false, + received_by: '', + delivery_date: '' }; const continuationSkeleton = { @@ -196,7 +204,11 @@ function mergeDefaults(skeleton: any, partial: any) { if (!partial) return skeleton; - return { ...skeleton, ...partial }; + // Filter out undefined values from partial to preserve skeleton defaults + const filtered = Object.fromEntries( + Object.entries(partial).filter(([_, value]) => value !== undefined) + ); + return { ...skeleton, ...filtered }; } // Referencias a los componentes de formulario para obtener sus datos @@ -503,8 +515,16 @@ } let isLoadingDefaults = $state(false); - let lastLoadedKey = $state( - data.defaultSettings + + // Compute initial key from source data to avoid state reference warning + const initialLoadedKey = data.defaultSettings?.InvoiceTopFieldsFormData + ? `${data.defaultSettings.InvoiceTopFieldsFormData.invoice_type || ''}-${data.defaultSettings.InvoiceTopFieldsFormData.operation_type || ''}` + : ''; + let lastLoadedKey = $state(initialLoadedKey); + + // Create a derived value for the current key to track changes reactively + let currentKey = $derived( + InvoiceTopFieldsFormData?.invoice_type && InvoiceTopFieldsFormData?.operation_type ? `${InvoiceTopFieldsFormData.invoice_type}-${InvoiceTopFieldsFormData.operation_type}` : '' ); @@ -518,7 +538,6 @@ ) return; - const currentKey = `${InvoiceTopFieldsFormData.invoice_type}-${InvoiceTopFieldsFormData.operation_type}`; if (currentKey === lastLoadedKey) return; isLoadingDefaults = true;