From 96821145e305eca23cdf107ef349402293a5b1c9 Mon Sep 17 00:00:00 2001 From: Josmar Soares Trigueiro Junior Date: Fri, 24 May 2024 15:58:45 -0300 Subject: [PATCH 1/2] fix: save edit, remove and add addresses the Cost Center at admin --- react/admin/CostCenterDetails.tsx | 112 ++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 7 deletions(-) diff --git a/react/admin/CostCenterDetails.tsx b/react/admin/CostCenterDetails.tsx index e5164c8a..89bc3984 100644 --- a/react/admin/CostCenterDetails.tsx +++ b/react/admin/CostCenterDetails.tsx @@ -305,6 +305,8 @@ const CostCenterDetails: FunctionComponent = () => { (item: any) => item.addressId === uid ) + setLoadingState(true) + let isDuplicatedError = false if (duplicated !== undefined) { @@ -333,6 +335,40 @@ const CostCenterDetails: FunctionComponent = () => { const newAddresses = [...addresses, newAddress] + const variables = { + id: params.id, + input: { + addresses: newAddresses + .sort(item => (item.checked ? -1 : 1)) + .map(item => { + return { + ...item, + checked: undefined, + } + }), + }, + } + + updateCostCenter({ variables }) + .then(() => { + showToast({ + variant: 'positive', + message: formatMessage(messages.toastUpdateSuccess), + }) + refetch() + handleSetAddresses(newAddresses) + setLoadingState(false) + handleCloseModals() + }) + .catch(error => { + console.error(error) + showToast({ + variant: 'critical', + message: formatMessage(messages.toastUpdateFailure), + }) + setLoadingState(false) + }) + setAddresses( newAddresses.map(item => { if (newAddressState.checked) { @@ -342,9 +378,6 @@ const CostCenterDetails: FunctionComponent = () => { return item }) ) - - setAddresses([...addresses, newAddress]) - handleCloseModals() } else { showToast({ variant: 'critical', @@ -386,8 +419,41 @@ const CostCenterDetails: FunctionComponent = () => { addressQuery: editAddressState.addressQuery.value, } - setAddresses(addressArray) - handleCloseModals() + setLoadingState(true) + + const variables = { + id: params.id, + input: { + addresses: addressArray + .sort(item => (item.checked ? -1 : 1)) + .map(item => { + return { + ...item, + checked: undefined, + } + }), + }, + } + + updateCostCenter({ variables }) + .then(() => { + showToast({ + variant: 'positive', + message: formatMessage(messages.toastUpdateSuccess), + }) + refetch() + handleSetAddresses(addressArray) + setLoadingState(false) + handleCloseModals() + }) + .catch(error => { + console.error(error) + showToast({ + variant: 'critical', + message: formatMessage(messages.toastUpdateFailure), + }) + setLoadingState(false) + }) } const handleDeleteAddress = () => { @@ -399,8 +465,40 @@ const CostCenterDetails: FunctionComponent = () => { ) addresses.splice(addressIndex, 1) - setAddresses(addressArray) - handleCloseModals() + + setLoadingState(true) + + const variables = { + id: params.id, + input: { + addresses: addresses.map(item => { + return { + ...item, + checked: undefined, + } + }), + }, + } + + updateCostCenter({ variables }) + .then(() => { + showToast({ + variant: 'positive', + message: formatMessage(messages.toastUpdateSuccess), + }) + refetch() + handleSetAddresses(addressArray) + setLoadingState(false) + handleCloseModals() + }) + .catch(error => { + console.error(error) + showToast({ + variant: 'critical', + message: formatMessage(messages.toastUpdateFailure), + }) + setLoadingState(false) + }) } const handleMarketingTags = (tagValue: string) => { From e55e7c6d38d810c25248e72e9f41b36946940901 Mon Sep 17 00:00:00 2001 From: Josmar Soares Trigueiro Junior Date: Fri, 24 May 2024 16:01:28 -0300 Subject: [PATCH 2/2] doc: updated changelog file with new change --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 492690af..531735c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed +- Save add, edit and delete address within the Cost Center in admin + +### Fixed + - Pagination bug on admin organization details collections assignment UI ### Added