fix: Wrong assignee displayed after switching conversations (#13501)
This commit is contained in:
@@ -31,7 +31,10 @@ const assignedAgent = computed({
|
|||||||
},
|
},
|
||||||
set(agent) {
|
set(agent) {
|
||||||
const agentId = agent ? agent.id : null;
|
const agentId = agent ? agent.id : null;
|
||||||
store.dispatch('setCurrentChatAssignee', agent);
|
store.dispatch('setCurrentChatAssignee', {
|
||||||
|
conversationId: currentChat.value?.id,
|
||||||
|
assignee: agent,
|
||||||
|
});
|
||||||
store.dispatch('assignAgent', {
|
store.dispatch('assignAgent', {
|
||||||
conversationId: currentChat.value?.id,
|
conversationId: currentChat.value?.id,
|
||||||
agentId,
|
agentId,
|
||||||
|
|||||||
@@ -85,7 +85,10 @@ export default {
|
|||||||
},
|
},
|
||||||
set(agent) {
|
set(agent) {
|
||||||
const agentId = agent ? agent.id : null;
|
const agentId = agent ? agent.id : null;
|
||||||
this.$store.dispatch('setCurrentChatAssignee', agent);
|
this.$store.dispatch('setCurrentChatAssignee', {
|
||||||
|
conversationId: this.currentChat.id,
|
||||||
|
assignee: agent,
|
||||||
|
});
|
||||||
this.$store
|
this.$store
|
||||||
.dispatch('assignAgent', {
|
.dispatch('assignAgent', {
|
||||||
conversationId: this.currentChat.id,
|
conversationId: this.currentChat.id,
|
||||||
|
|||||||
@@ -212,14 +212,17 @@ const actions = {
|
|||||||
conversationId,
|
conversationId,
|
||||||
agentId,
|
agentId,
|
||||||
});
|
});
|
||||||
dispatch('setCurrentChatAssignee', response.data);
|
dispatch('setCurrentChatAssignee', {
|
||||||
|
conversationId,
|
||||||
|
assignee: response.data,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Handle error
|
// Handle error
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setCurrentChatAssignee({ commit }, assignee) {
|
setCurrentChatAssignee({ commit }, { conversationId, assignee }) {
|
||||||
commit(types.ASSIGN_AGENT, assignee);
|
commit(types.ASSIGN_AGENT, { conversationId, assignee });
|
||||||
},
|
},
|
||||||
|
|
||||||
assignTeam: async ({ dispatch }, { conversationId, teamId }) => {
|
assignTeam: async ({ dispatch }, { conversationId, teamId }) => {
|
||||||
|
|||||||
@@ -108,9 +108,11 @@ export const mutations = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
[types.ASSIGN_AGENT](_state, assignee) {
|
[types.ASSIGN_AGENT](_state, { conversationId, assignee }) {
|
||||||
const [chat] = getSelectedChatConversation(_state);
|
const chat = getConversationById(_state)(conversationId);
|
||||||
chat.meta.assignee = assignee;
|
if (chat) {
|
||||||
|
chat.meta.assignee = assignee;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
[types.ASSIGN_TEAM](_state, { team, conversationId }) {
|
[types.ASSIGN_TEAM](_state, { team, conversationId }) {
|
||||||
@@ -285,8 +287,10 @@ export const mutations = {
|
|||||||
|
|
||||||
// Update assignee on action cable message
|
// Update assignee on action cable message
|
||||||
[types.UPDATE_ASSIGNEE](_state, payload) {
|
[types.UPDATE_ASSIGNEE](_state, payload) {
|
||||||
const [chat] = _state.allConversations.filter(c => c.id === payload.id);
|
const chat = getConversationById(_state)(payload.id);
|
||||||
chat.meta.assignee = payload.assignee;
|
if (chat) {
|
||||||
|
chat.meta.assignee = payload.assignee;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
[types.UPDATE_CONVERSATION_CONTACT](_state, { conversationId, ...payload }) {
|
[types.UPDATE_CONVERSATION_CONTACT](_state, { conversationId, ...payload }) {
|
||||||
|
|||||||
@@ -355,22 +355,26 @@ describe('#actions', () => {
|
|||||||
axios.post.mockResolvedValue({
|
axios.post.mockResolvedValue({
|
||||||
data: { id: 1, name: 'User' },
|
data: { id: 1, name: 'User' },
|
||||||
});
|
});
|
||||||
await actions.assignAgent({ commit }, { conversationId: 1, agentId: 1 });
|
await actions.assignAgent(
|
||||||
expect(commit).toHaveBeenCalledTimes(0);
|
{ dispatch },
|
||||||
expect(commit.mock.calls).toEqual([]);
|
{ conversationId: 1, agentId: 1 }
|
||||||
|
);
|
||||||
|
expect(dispatch).toHaveBeenCalledWith('setCurrentChatAssignee', {
|
||||||
|
conversationId: 1,
|
||||||
|
assignee: { id: 1, name: 'User' },
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#setCurrentChatAssignee', () => {
|
describe('#setCurrentChatAssignee', () => {
|
||||||
it('sends correct mutations if assignment is successful', async () => {
|
it('sends correct mutations if assignment is successful', async () => {
|
||||||
axios.post.mockResolvedValue({
|
const payload = {
|
||||||
data: { id: 1, name: 'User' },
|
conversationId: 1,
|
||||||
});
|
assignee: { id: 1, name: 'User' },
|
||||||
await actions.setCurrentChatAssignee({ commit }, { id: 1, name: 'User' });
|
};
|
||||||
|
await actions.setCurrentChatAssignee({ commit }, payload);
|
||||||
expect(commit).toHaveBeenCalledTimes(1);
|
expect(commit).toHaveBeenCalledTimes(1);
|
||||||
expect(commit.mock.calls).toEqual([
|
expect(commit.mock.calls).toEqual([['ASSIGN_AGENT', payload]]);
|
||||||
['ASSIGN_AGENT', { id: 1, name: 'User' }],
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -699,15 +699,22 @@ describe('#mutations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#ASSIGN_AGENT', () => {
|
describe('#ASSIGN_AGENT', () => {
|
||||||
it('should assign agent to selected conversation', () => {
|
it('should assign agent to the correct conversation by ID', () => {
|
||||||
const assignee = { id: 1, name: 'Agent' };
|
const assignee = { id: 1, name: 'Agent' };
|
||||||
const state = {
|
const state = {
|
||||||
allConversations: [{ id: 1, meta: {} }],
|
allConversations: [
|
||||||
selectedChatId: 1,
|
{ id: 1, meta: {} },
|
||||||
|
{ id: 2, meta: {} },
|
||||||
|
],
|
||||||
|
selectedChatId: 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
mutations[types.ASSIGN_AGENT](state, assignee);
|
mutations[types.ASSIGN_AGENT](state, {
|
||||||
|
conversationId: 1,
|
||||||
|
assignee,
|
||||||
|
});
|
||||||
expect(state.allConversations[0].meta.assignee).toEqual(assignee);
|
expect(state.allConversations[0].meta.assignee).toEqual(assignee);
|
||||||
|
expect(state.allConversations[1].meta.assignee).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user