{
const isNew = !match.params.id;
- const loadedContact = resources?.contact?.records?.[0];
+ const isPrivilegedContactUrl = match.path.includes(PRIVILEGED_CONTACT_URL_PATH);
+ const contactResources = isPrivilegedContactUrl ? 'privilegedContact' : 'contact';
+ const loadedContact = get(resources[contactResources], 'records[0]');
const categories = resources?.[DICT_CATEGORIES]?.records;
const [translatedCategories] = useTranslatedCategories(categories);
const contactsOrganization = resources?.contactsOrg?.records?.[0];
@@ -36,12 +41,12 @@ export const EditContactContainer = ({
if (onClose) {
onClose(orgId, contactId);
} else {
- history.push(getBackPath(orgId, contactId, 'contacts'));
+ history.push(getBackPath(orgId, contactId, isPrivilegedContactUrl ? PRIVILEGED_CONTACT_URL_PATH : 'contacts'));
}
- }, [match.params.id, onClose, history, orgId]);
+ }, [match.params.id, onClose, orgId, history, isPrivilegedContactUrl]);
const onSubmit = useCallback(contactValues => {
- saveContact(mutator, contactValues, contactsOrganization)
+ saveContact(mutator, contactValues, contactsOrganization, isPrivilegedContactUrl)
.then(({ id }) => {
showMessage('ui-organizations.contacts.message.saved.success', 'success');
onCloseForm(id);
@@ -63,6 +68,7 @@ export const EditContactContainer = ({
const contact = isNew ? {} : loadedContact;
const { firstName, lastName } = contact;
const name = `${lastName}, ${firstName}`;
+
const paneTitle = isNew
?
: ;
@@ -82,6 +88,7 @@ EditContactContainer.manifest = Object.freeze({
contact: contactResource,
[DICT_CATEGORIES]: categoriesResource,
contactsOrg: organizationResource,
+ privilegedContact: privilegedContactResource,
});
EditContactContainer.propTypes = {
diff --git a/src/contacts/EditContact/EditContactContainer.test.js b/src/contacts/EditContact/EditContactContainer.test.js
index 8d986dc7..0ed34708 100644
--- a/src/contacts/EditContact/EditContactContainer.test.js
+++ b/src/contacts/EditContact/EditContactContainer.test.js
@@ -9,6 +9,7 @@ import { DICT_CATEGORIES } from '../../common/constants';
import { saveContact } from './util';
import EditContact from './EditContact';
import { EditContactContainer } from './EditContactContainer';
+import { PRIVILEGED_CONTACT_URL_PATH } from '../constants';
jest.mock('./util', () => ({
saveContact: jest.fn(),
@@ -29,6 +30,7 @@ const defaultProps = {
[DICT_CATEGORIES]: {
records: [{ value: 'Customer Service', id: 'f52ceea4-8e35' }],
},
+ privilegedContact: { records: [contact] },
},
showMessage: jest.fn(),
onClose: jest.fn(),
@@ -80,4 +82,37 @@ describe('EditContactContainer', () => {
expect(saveContact).toHaveBeenCalled();
});
+
+ describe('Privileged contact actions', () => {
+ const props = {
+ ...defaultProps,
+ match: {
+ ...defaultProps.match,
+ path: `/contacts/view/:id/${PRIVILEGED_CONTACT_URL_PATH}`,
+ },
+ onClose: undefined,
+ };
+
+ it('should save privileged contacts', async () => {
+ saveContact.mockClear().mockReturnValue(Promise.resolve());
+
+ renderEditContactContainer(props);
+
+ await screen.findByText('EditContact');
+
+ EditContact.mock.calls[0][0].onSubmit({});
+
+ expect(saveContact).toHaveBeenCalled();
+ });
+
+ it('should redirect to org details when form is closed', async () => {
+ renderEditContactContainer(props);
+
+ await screen.findByText('EditContact');
+
+ EditContact.mock.calls[0][0].onClose();
+
+ expect(historyMock.push).toHaveBeenCalledWith('/organizations/orgId/privileged-contacts/id/view');
+ });
+ });
});
diff --git a/src/contacts/EditContact/util.js b/src/contacts/EditContact/util.js
index 0b236b0c..2689bbab 100644
--- a/src/contacts/EditContact/util.js
+++ b/src/contacts/EditContact/util.js
@@ -1,7 +1,8 @@
// eslint-disable-next-line import/prefer-default-export
-export const saveContact = (mutator, contact, org) => {
+export const saveContact = (mutator, contact, org, isPrivilegedContactUrl = false) => {
const isNew = !contact.id;
- const httpMethod = isNew ? mutator.contact.POST : mutator.contact.PUT;
+ const currentMutator = isPrivilegedContactUrl ? mutator.privilegedContact : mutator.contact;
+ const httpMethod = isNew ? currentMutator.POST : currentMutator.PUT;
return httpMethod(contact)
.then(savedContact => {
diff --git a/src/contacts/EditContact/util.test.js b/src/contacts/EditContact/util.test.js
index 0775f6f8..d3eeb1a9 100644
--- a/src/contacts/EditContact/util.test.js
+++ b/src/contacts/EditContact/util.test.js
@@ -1,47 +1,56 @@
import { saveContact } from './util';
+const contactId = 'contactId';
+const contact = { name: 'Mark' };
+const contactWithId = { id: contactId, name: 'Mark' };
+const org = { id: 'org1', name: 'Amazon', contacts: [] };
+
+const contactMutator = {
+ contact: {
+ POST: jest.fn().mockReturnValue(Promise.resolve({ ...contact, id: contactId })),
+ PUT: jest.fn().mockReturnValue(Promise.resolve()),
+ },
+ privilegedContact: {
+ PUT: jest.fn().mockReturnValue(Promise.resolve()),
+ POST: jest.fn().mockReturnValue(Promise.resolve({ ...contact, id: contactId })),
+ },
+ contactsOrg: {
+ PUT: jest.fn().mockReturnValue(Promise.resolve()),
+ },
+};
+
describe('EditContact utils', () => {
it('should create contact when contact without id', async () => {
- const contact = { name: 'Mark' };
- const mutator = {
- contact: {
- POST: jest.fn().mockReturnValue(Promise.resolve()),
- },
- };
-
- await saveContact(mutator, contact);
+ await saveContact(contactMutator, contact);
- expect(mutator.contact.POST).toHaveBeenCalledWith(contact);
+ expect(contactMutator.contact.POST).toHaveBeenCalledWith(contact);
});
it('should update contact when contact with id', async () => {
- const contact = { id: 'contactId', name: 'Mark' };
- const mutator = {
- contact: {
- PUT: jest.fn().mockReturnValue(Promise.resolve()),
- },
- };
-
- await saveContact(mutator, contact);
+ await saveContact(contactMutator, contactWithId);
- expect(mutator.contact.PUT).toHaveBeenCalledWith(contact);
+ expect(contactMutator.contact.PUT).toHaveBeenCalledWith(contactWithId);
});
it('should assign contact to org when contact is saved successfully and org is provided', async () => {
- const contactId = 'contactId';
- const contact = { name: 'Mark' };
- const org = { id: 'org1', name: 'Amazon', contacts: [] };
- const mutator = {
- contact: {
- POST: jest.fn().mockReturnValue(Promise.resolve({ ...contact, id: contactId })),
- },
- contactsOrg: {
- PUT: jest.fn().mockReturnValue(Promise.resolve()),
- },
- };
-
- await saveContact(mutator, contact, org);
-
- expect(mutator.contactsOrg.PUT).toHaveBeenCalledWith({ ...org, contacts: [contactId] });
+ await saveContact(contactMutator, contact, org);
+
+ expect(contactMutator.contactsOrg.PUT).toHaveBeenCalledWith({ ...org, contacts: [contactId] });
+ });
+
+ it('should create privileged contact', async () => {
+ const isPrivilegedContactUrl = true;
+
+ await saveContact(contactMutator, contact, org, isPrivilegedContactUrl);
+
+ expect(contactMutator.privilegedContact.POST).toHaveBeenCalledWith(contact);
+ });
+
+ it('should update privileged contact when with id', async () => {
+ const isPrivilegedContactUrl = true;
+
+ await saveContact(contactMutator, contactWithId, org, isPrivilegedContactUrl);
+
+ expect(contactMutator.privilegedContact.PUT).toHaveBeenCalledWith(contactWithId);
});
});
diff --git a/src/contacts/ViewContact/ViewContact.js b/src/contacts/ViewContact/ViewContact.js
index 59fad6a2..3d56a84e 100644
--- a/src/contacts/ViewContact/ViewContact.js
+++ b/src/contacts/ViewContact/ViewContact.js
@@ -34,6 +34,7 @@ import { ORGANIZATIONS_ROUTE } from '../../common/constants';
import {
CONTACT_PERSON_ACCORDIONS,
CONTACT_PERSON_ACCORDION_LABELS,
+ PRIVILEGED_CONTACT_URL_PATH,
} from '../constants';
import ContactDetails from './ContactDetails';
import ContactAddresses from './ContactAddresses';
@@ -51,6 +52,7 @@ const ViewContact = ({
}) => {
const history = useHistory();
const accordionStatusRef = useRef();
+ const isPrivilegedContactUrl = history.location?.pathname?.includes(PRIVILEGED_CONTACT_URL_PATH);
const stripes = useStripes();
@@ -81,6 +83,7 @@ const ViewContact = ({
// eslint-disable-next-line react/prop-types
const getActionMenu = ({ onToggle }) => {
const contactId = contact.id;
+ const isUnassignVisible = contactId && !isPrivilegedContactUrl;
return (
@@ -95,7 +98,7 @@ const ViewContact = ({
- {contactId && (
+ {isUnassignVisible && (