From e65ea24360123eacb9bbd000278265fb91b307c5 Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Tue, 10 Feb 2026 15:23:55 +0530 Subject: [PATCH] fix: Wrong assignee displayed after switching conversations (#13501) --- .../widgets/conversation/ReplyBoxBanner.vue | 5 +++- .../conversation/ConversationAction.vue | 5 +++- .../store/modules/conversations/actions.js | 9 ++++--- .../store/modules/conversations/index.js | 14 +++++++---- .../specs/conversations/actions.spec.js | 24 +++++++++++-------- .../specs/conversations/mutations.spec.js | 15 ++++++++---- 6 files changed, 48 insertions(+), 24 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/conversation/ReplyBoxBanner.vue b/app/javascript/dashboard/components/widgets/conversation/ReplyBoxBanner.vue index d80910343..8be715a4f 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ReplyBoxBanner.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ReplyBoxBanner.vue @@ -31,7 +31,10 @@ const assignedAgent = computed({ }, set(agent) { const agentId = agent ? agent.id : null; - store.dispatch('setCurrentChatAssignee', agent); + store.dispatch('setCurrentChatAssignee', { + conversationId: currentChat.value?.id, + assignee: agent, + }); store.dispatch('assignAgent', { conversationId: currentChat.value?.id, agentId, diff --git a/app/javascript/dashboard/routes/dashboard/conversation/ConversationAction.vue b/app/javascript/dashboard/routes/dashboard/conversation/ConversationAction.vue index 9a7004c5d..35d985c77 100644 --- a/app/javascript/dashboard/routes/dashboard/conversation/ConversationAction.vue +++ b/app/javascript/dashboard/routes/dashboard/conversation/ConversationAction.vue @@ -85,7 +85,10 @@ export default { }, set(agent) { const agentId = agent ? agent.id : null; - this.$store.dispatch('setCurrentChatAssignee', agent); + this.$store.dispatch('setCurrentChatAssignee', { + conversationId: this.currentChat.id, + assignee: agent, + }); this.$store .dispatch('assignAgent', { conversationId: this.currentChat.id, diff --git a/app/javascript/dashboard/store/modules/conversations/actions.js b/app/javascript/dashboard/store/modules/conversations/actions.js index cc3e9d428..0c4c084e0 100644 --- a/app/javascript/dashboard/store/modules/conversations/actions.js +++ b/app/javascript/dashboard/store/modules/conversations/actions.js @@ -212,14 +212,17 @@ const actions = { conversationId, agentId, }); - dispatch('setCurrentChatAssignee', response.data); + dispatch('setCurrentChatAssignee', { + conversationId, + assignee: response.data, + }); } catch (error) { // Handle error } }, - setCurrentChatAssignee({ commit }, assignee) { - commit(types.ASSIGN_AGENT, assignee); + setCurrentChatAssignee({ commit }, { conversationId, assignee }) { + commit(types.ASSIGN_AGENT, { conversationId, assignee }); }, assignTeam: async ({ dispatch }, { conversationId, teamId }) => { diff --git a/app/javascript/dashboard/store/modules/conversations/index.js b/app/javascript/dashboard/store/modules/conversations/index.js index 3c4003af4..84be116fe 100644 --- a/app/javascript/dashboard/store/modules/conversations/index.js +++ b/app/javascript/dashboard/store/modules/conversations/index.js @@ -108,9 +108,11 @@ export const mutations = { } }, - [types.ASSIGN_AGENT](_state, assignee) { - const [chat] = getSelectedChatConversation(_state); - chat.meta.assignee = assignee; + [types.ASSIGN_AGENT](_state, { conversationId, assignee }) { + const chat = getConversationById(_state)(conversationId); + if (chat) { + chat.meta.assignee = assignee; + } }, [types.ASSIGN_TEAM](_state, { team, conversationId }) { @@ -285,8 +287,10 @@ export const mutations = { // Update assignee on action cable message [types.UPDATE_ASSIGNEE](_state, payload) { - const [chat] = _state.allConversations.filter(c => c.id === payload.id); - chat.meta.assignee = payload.assignee; + const chat = getConversationById(_state)(payload.id); + if (chat) { + chat.meta.assignee = payload.assignee; + } }, [types.UPDATE_CONVERSATION_CONTACT](_state, { conversationId, ...payload }) { diff --git a/app/javascript/dashboard/store/modules/specs/conversations/actions.spec.js b/app/javascript/dashboard/store/modules/specs/conversations/actions.spec.js index 87ec5ced7..fa052ec1b 100644 --- a/app/javascript/dashboard/store/modules/specs/conversations/actions.spec.js +++ b/app/javascript/dashboard/store/modules/specs/conversations/actions.spec.js @@ -355,22 +355,26 @@ describe('#actions', () => { axios.post.mockResolvedValue({ data: { id: 1, name: 'User' }, }); - await actions.assignAgent({ commit }, { conversationId: 1, agentId: 1 }); - expect(commit).toHaveBeenCalledTimes(0); - expect(commit.mock.calls).toEqual([]); + await actions.assignAgent( + { dispatch }, + { conversationId: 1, agentId: 1 } + ); + expect(dispatch).toHaveBeenCalledWith('setCurrentChatAssignee', { + conversationId: 1, + assignee: { id: 1, name: 'User' }, + }); }); }); describe('#setCurrentChatAssignee', () => { it('sends correct mutations if assignment is successful', async () => { - axios.post.mockResolvedValue({ - data: { id: 1, name: 'User' }, - }); - await actions.setCurrentChatAssignee({ commit }, { id: 1, name: 'User' }); + const payload = { + conversationId: 1, + assignee: { id: 1, name: 'User' }, + }; + await actions.setCurrentChatAssignee({ commit }, payload); expect(commit).toHaveBeenCalledTimes(1); - expect(commit.mock.calls).toEqual([ - ['ASSIGN_AGENT', { id: 1, name: 'User' }], - ]); + expect(commit.mock.calls).toEqual([['ASSIGN_AGENT', payload]]); }); }); diff --git a/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js b/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js index 0c04d2f61..01abf05f7 100644 --- a/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js +++ b/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js @@ -699,15 +699,22 @@ describe('#mutations', () => { }); 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 state = { - allConversations: [{ id: 1, meta: {} }], - selectedChatId: 1, + allConversations: [ + { 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[1].meta.assignee).toBeUndefined(); }); });