Skip to content

Commit

Permalink
UIORGS-397 Update the correct field in the organization when creating…
Browse files Browse the repository at this point in the history
… a new privileged contact (#598)
  • Loading branch information
usavkov-epam authored Jan 4, 2024
1 parent e754248 commit f2fe2f0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/contacts/EditContact/util.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// eslint-disable-next-line import/prefer-default-export
import get from 'lodash/get';

export const saveContact = (mutator, contact, org, isPrivilegedContactUrl = false) => {
const isNew = !contact.id;
const currentMutator = isPrivilegedContactUrl ? mutator.privilegedContact : mutator.contact;
const httpMethod = isNew ? currentMutator.POST : currentMutator.PUT;
const fieldName = isPrivilegedContactUrl ? 'privilegedContacts' : 'contacts';

return httpMethod(contact)
.then(savedContact => {
if (isNew && org && org.id) {
mutator.contactsOrg.PUT({
...org,
contacts: [...org.contacts, savedContact.id],
[fieldName]: [...get(org, fieldName, []), savedContact.id],
});
}

Expand Down

0 comments on commit f2fe2f0

Please sign in to comment.