From 3783cdeed4313fe907d48842d90841f89c8348bd Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 26 Mar 2025 12:03:46 +0100 Subject: [PATCH 1/5] fix: fixed buttons disabled when there are no changes --- src/pages/Customer/components/CustomerAddressEdit.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Customer/components/CustomerAddressEdit.vue b/src/pages/Customer/components/CustomerAddressEdit.vue index f852c160a..88abcaa77 100644 --- a/src/pages/Customer/components/CustomerAddressEdit.vue +++ b/src/pages/Customer/components/CustomerAddressEdit.vue @@ -180,7 +180,7 @@ function handleLocation(data, location) { Date: Wed, 26 Mar 2025 12:32:22 +0100 Subject: [PATCH 2/5] refactor: manage every nullable option --- .../Customer/components/CustomerAddressEdit.vue | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pages/Customer/components/CustomerAddressEdit.vue b/src/pages/Customer/components/CustomerAddressEdit.vue index 88abcaa77..1f7b4c1e8 100644 --- a/src/pages/Customer/components/CustomerAddressEdit.vue +++ b/src/pages/Customer/components/CustomerAddressEdit.vue @@ -93,10 +93,20 @@ const updateAddressTicket = async () => { }; const updateObservations = async (payload) => { + if (isPayloadEmpty(payload)) return; await axios.post('AddressObservations/crud', payload); notes.value = []; deletes.value = []; }; + +function isPayloadEmpty(payload) { + return ['creates', 'deletes', 'updates'].every( + (prop) => + !payload[prop] || + payload[prop].length === 0 || + payload[prop].every((item) => item === undefined || item === null), + ); +} async function updateAll({ data, payload }) { await updateObservations(payload); await updateAddress(data); @@ -180,7 +190,7 @@ function handleLocation(data, location) { Date: Wed, 26 Mar 2025 13:51:03 +0100 Subject: [PATCH 3/5] refactor: clean payload --- .../components/CustomerAddressEdit.vue | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/pages/Customer/components/CustomerAddressEdit.vue b/src/pages/Customer/components/CustomerAddressEdit.vue index 1f7b4c1e8..c89e7e2e9 100644 --- a/src/pages/Customer/components/CustomerAddressEdit.vue +++ b/src/pages/Customer/components/CustomerAddressEdit.vue @@ -93,20 +93,28 @@ const updateAddressTicket = async () => { }; const updateObservations = async (payload) => { - if (isPayloadEmpty(payload)) return; + cleanPayload(payload); await axios.post('AddressObservations/crud', payload); notes.value = []; deletes.value = []; }; -function isPayloadEmpty(payload) { - return ['creates', 'deletes', 'updates'].every( - (prop) => - !payload[prop] || - payload[prop].length === 0 || - payload[prop].every((item) => item === undefined || item === null), - ); +function cleanPayload(payload) { + ['creates', 'deletes', 'updates'].forEach((prop) => { + if (prop === 'creates' || prop === 'updates') { + payload[prop] = payload[prop].filter( + (item) => item.description !== '' && item.observationTypeFk !== '', + ); + } + if (prop === 'deletes') { + payload[prop] = payload[prop].filter( + (item) => item !== null && item !== undefined, + ); + } + return payload[prop]; + }); } + async function updateAll({ data, payload }) { await updateObservations(payload); await updateAddress(data); -- 2.40.1 From e353f7916af14d781fc5eb23bead0a231bba20e9 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 26 Mar 2025 14:15:01 +0100 Subject: [PATCH 4/5] perf: clean payload --- src/pages/Customer/components/CustomerAddressEdit.vue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/Customer/components/CustomerAddressEdit.vue b/src/pages/Customer/components/CustomerAddressEdit.vue index c89e7e2e9..31a930341 100644 --- a/src/pages/Customer/components/CustomerAddressEdit.vue +++ b/src/pages/Customer/components/CustomerAddressEdit.vue @@ -105,8 +105,7 @@ function cleanPayload(payload) { payload[prop] = payload[prop].filter( (item) => item.description !== '' && item.observationTypeFk !== '', ); - } - if (prop === 'deletes') { + } else { payload[prop] = payload[prop].filter( (item) => item !== null && item !== undefined, ); -- 2.40.1 From 60899ef2d255f6bf9443121de25ece33fdc64316 Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 27 Mar 2025 15:03:11 +0100 Subject: [PATCH 5/5] perf: clean payload --- src/pages/Customer/components/CustomerAddressEdit.vue | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/Customer/components/CustomerAddressEdit.vue b/src/pages/Customer/components/CustomerAddressEdit.vue index 31a930341..bc76f5985 100644 --- a/src/pages/Customer/components/CustomerAddressEdit.vue +++ b/src/pages/Customer/components/CustomerAddressEdit.vue @@ -93,8 +93,7 @@ const updateAddressTicket = async () => { }; const updateObservations = async (payload) => { - cleanPayload(payload); - await axios.post('AddressObservations/crud', payload); + await axios.post('AddressObservations/crud', cleanPayload(payload)); notes.value = []; deletes.value = []; }; @@ -110,8 +109,8 @@ function cleanPayload(payload) { (item) => item !== null && item !== undefined, ); } - return payload[prop]; }); + return payload; } async function updateAll({ data, payload }) { -- 2.40.1