Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/save edit address data admin #160

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
112 changes: 105 additions & 7 deletions react/admin/CostCenterDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ const CostCenterDetails: FunctionComponent = () => {
(item: any) => item.addressId === uid
)

setLoadingState(true)

let isDuplicatedError = false

if (duplicated !== undefined) {
Expand Down Expand Up @@ -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) {
Expand All @@ -342,9 +378,6 @@ const CostCenterDetails: FunctionComponent = () => {
return item
})
)

setAddresses([...addresses, newAddress])
handleCloseModals()
} else {
showToast({
variant: 'critical',
Expand Down Expand Up @@ -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 = () => {
Expand All @@ -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) => {
Expand Down
Loading