feat: Render contact custom attributes in contact/conversation sidebar (#3310)
This commit is contained in:
@@ -24,10 +24,10 @@ export const getters = {
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
get: async function getAttributesByModel({ commit }, modelId) {
|
||||
get: async function getAttributesByModel({ commit }) {
|
||||
commit(types.SET_CUSTOM_ATTRIBUTE_UI_FLAG, { isFetching: true });
|
||||
try {
|
||||
const response = await AttributeAPI.getAttributesByModel(modelId);
|
||||
const response = await AttributeAPI.getAttributesByModel();
|
||||
commit(types.SET_CUSTOM_ATTRIBUTE, response.data);
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
|
||||
@@ -110,6 +110,18 @@ export const actions = {
|
||||
}
|
||||
},
|
||||
|
||||
deleteCustomAttributes: async ({ commit }, { id, customAttributes }) => {
|
||||
try {
|
||||
const response = await ContactAPI.destroyCustomAttributes(
|
||||
id,
|
||||
customAttributes
|
||||
);
|
||||
commit(types.EDIT_CONTACT, response.data.payload);
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
}
|
||||
},
|
||||
|
||||
fetchContactableInbox: async ({ commit }, id) => {
|
||||
commit(types.SET_CONTACT_UI_FLAG, { isFetchingInboxes: true });
|
||||
try {
|
||||
|
||||
@@ -206,4 +206,24 @@ describe('#actions', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#deleteCustomAttributes', () => {
|
||||
it('sends correct mutations if API is success', async () => {
|
||||
axios.post.mockResolvedValue({ data: { payload: contactList[0] } });
|
||||
await actions.deleteCustomAttributes(
|
||||
{ commit },
|
||||
{ id: 1, customAttributes: ['cloud-customer'] }
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([[types.EDIT_CONTACT, contactList[0]]]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.patch.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(
|
||||
actions.deleteCustomAttributes(
|
||||
{ commit },
|
||||
{ id: 1, customAttributes: ['cloud-customer'] }
|
||||
)
|
||||
).rejects.toThrow(Error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user