feat: Render conversation custom attributes (#3065)
This commit is contained in:
@@ -278,6 +278,25 @@ const actions = {
|
||||
throw new Error(error);
|
||||
}
|
||||
},
|
||||
|
||||
updateCustomAttributes: async (
|
||||
{ commit },
|
||||
{ conversationId, customAttributes }
|
||||
) => {
|
||||
try {
|
||||
const response = await ConversationApi.updateCustomAttributes({
|
||||
conversationId,
|
||||
customAttributes,
|
||||
});
|
||||
const { custom_attributes } = response.data;
|
||||
commit(
|
||||
types.default.UPDATE_CONVERSATION_CUSTOM_ATTRIBUTES,
|
||||
custom_attributes
|
||||
);
|
||||
} catch (error) {
|
||||
// Handle error
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default actions;
|
||||
|
||||
@@ -69,6 +69,14 @@ export const mutations = {
|
||||
Vue.set(chat.meta, 'team', team);
|
||||
},
|
||||
|
||||
[types.default.UPDATE_CONVERSATION_CUSTOM_ATTRIBUTES](
|
||||
_state,
|
||||
custom_attributes
|
||||
) {
|
||||
const [chat] = getSelectedChatConversation(_state);
|
||||
Vue.set(chat, 'custom_attributes', custom_attributes);
|
||||
},
|
||||
|
||||
[types.default.CHANGE_CONVERSATION_STATUS](
|
||||
_state,
|
||||
{ conversationId, status, snoozedUntil }
|
||||
|
||||
@@ -281,4 +281,25 @@ describe('#deleteMessage', () => {
|
||||
).rejects.toThrow(Error);
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
});
|
||||
|
||||
describe('#updateCustomAttributes', () => {
|
||||
it('update conversation custom attributes', async () => {
|
||||
axios.post.mockResolvedValue({
|
||||
data: { custom_attributes: { order_d: '1001' } },
|
||||
});
|
||||
await actions.updateCustomAttributes(
|
||||
{ commit },
|
||||
{
|
||||
conversationId: 1,
|
||||
customAttributes: { order_d: '1001' },
|
||||
}
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[
|
||||
types.default.UPDATE_CONVERSATION_CUSTOM_ATTRIBUTES,
|
||||
{ order_d: '1001' },
|
||||
],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -186,5 +186,19 @@ describe('#mutations', () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
describe('#UPDATE_CONVERSATION_CUSTOM_ATTRIBUTES', () => {
|
||||
it('update conversation custom attributes', () => {
|
||||
const custom_attributes = { order_id: 1001 };
|
||||
const state = { allConversations: [{ id: 1 }], selectedChatId: 1 };
|
||||
mutations[types.UPDATE_CONVERSATION_CUSTOM_ATTRIBUTES](state, {
|
||||
conversationId: 1,
|
||||
custom_attributes,
|
||||
});
|
||||
expect(
|
||||
state.allConversations[0].custom_attributes.custom_attributes
|
||||
).toEqual(custom_attributes);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user