+
@@ -27,11 +36,17 @@
-
diff --git a/app/javascript/dashboard/store/modules/contacts/actions.js b/app/javascript/dashboard/store/modules/contacts/actions.js
index 96a7c811a..801157bb4 100644
--- a/app/javascript/dashboard/store/modules/contacts/actions.js
+++ b/app/javascript/dashboard/store/modules/contacts/actions.js
@@ -4,6 +4,7 @@ import {
} from 'shared/helpers/CustomErrors';
import types from '../../mutation-types';
import ContactAPI from '../../../api/contacts';
+import AccountActionsAPI from '../../../api/accountActions';
export const actions = {
search: async ({ commit }, { search, page, sortAttr, label }) => {
@@ -137,6 +138,18 @@ export const actions = {
commit(types.SET_CONTACT_ITEM, data);
},
+ merge: async ({ commit }, { childId, parentId }) => {
+ commit(types.SET_CONTACT_UI_FLAG, { isMerging: true });
+ try {
+ const response = await AccountActionsAPI.merge(parentId, childId);
+ commit(types.SET_CONTACT_ITEM, response.data);
+ } catch (error) {
+ throw new Error(error);
+ } finally {
+ commit(types.SET_CONTACT_UI_FLAG, { isMerging: false });
+ }
+ },
+
deleteContactThroughConversations: ({ commit }, id) => {
commit(types.DELETE_CONTACT, id);
commit(types.CLEAR_CONTACT_CONVERSATIONS, id, { root: true });
diff --git a/app/javascript/dashboard/store/modules/contacts/index.js b/app/javascript/dashboard/store/modules/contacts/index.js
index f1982e4be..b2657ca78 100644
--- a/app/javascript/dashboard/store/modules/contacts/index.js
+++ b/app/javascript/dashboard/store/modules/contacts/index.js
@@ -13,6 +13,7 @@ const state = {
isFetchingItem: false,
isFetchingInboxes: false,
isUpdating: false,
+ isMerging: false,
isDeleting: false,
},
sortOrder: [],
diff --git a/app/javascript/dashboard/store/modules/specs/contacts/actions.spec.js b/app/javascript/dashboard/store/modules/specs/contacts/actions.spec.js
index 03d49d8d0..dc49f4731 100644
--- a/app/javascript/dashboard/store/modules/specs/contacts/actions.spec.js
+++ b/app/javascript/dashboard/store/modules/specs/contacts/actions.spec.js
@@ -168,6 +168,30 @@ describe('#actions', () => {
});
});
+ describe('#merge', () => {
+ it('sends correct mutations if API is success', async () => {
+ axios.post.mockResolvedValue({
+ data: contactList[0],
+ });
+ await actions.merge({ commit }, { childId: 0, parentId: 1 });
+ expect(commit.mock.calls).toEqual([
+ [types.SET_CONTACT_UI_FLAG, { isMerging: true }],
+ [types.SET_CONTACT_ITEM, contactList[0]],
+ [types.SET_CONTACT_UI_FLAG, { isMerging: false }],
+ ]);
+ });
+ it('sends correct actions if API is error', async () => {
+ axios.post.mockRejectedValue({ message: 'Incorrect header' });
+ await expect(
+ actions.merge({ commit }, { childId: 0, parentId: 1 })
+ ).rejects.toThrow(Error);
+ expect(commit.mock.calls).toEqual([
+ [types.SET_CONTACT_UI_FLAG, { isMerging: true }],
+ [types.SET_CONTACT_UI_FLAG, { isMerging: false }],
+ ]);
+ });
+ });
+
describe('#deleteContactThroughConversations', () => {
it('returns correct mutations', () => {
actions.deleteContactThroughConversations({ commit }, contactList[0].id);