Skip to content

Commit

Permalink
fix: remove deleted address from contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
fterra-encora committed Oct 17, 2023
1 parent 244f76c commit e8d74c4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion frontend/src/pages/bceidform/AddressWizardStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,22 @@ const updateAddress = (value: Address | undefined, index: number) => {
if (value) formData.location.addresses[index] = value;
else {
const addressesCopy: Address[] = [...formData.location.addresses];
addressesCopy.splice(index, 1);
const removedAddressArray = addressesCopy.splice(index, 1);
formData.location.addresses = addressesCopy;
// Remove the deleted address from the contacts that are associated to it.
// (the condition is just a sanity check)
if (removedAddressArray.length > 0) {
const removedAddress = removedAddressArray[0];
formData.location.contacts.forEach(contact => {
const indexWithinContact = contact.locationNames.findIndex(
(locationName) => locationName.text === removedAddress.locationName,
);
if (indexWithinContact !== -1) {
contact.locationNames.splice(indexWithinContact, 1);
}
})
}
}
revalidate.value = !revalidate.value;
}
Expand Down

0 comments on commit e8d74c4

Please sign in to comment.