mirror of
https://github.com/lingble/chatwoot.git
synced 2025-12-15 18:27:14 +00:00
fix: Update the relevant agent presence only (#5220)
This commit is contained in:
@@ -35,9 +35,6 @@ export const getters = {
|
||||
};
|
||||
return status;
|
||||
},
|
||||
getAgentsCount($state) {
|
||||
return $state.records.length;
|
||||
},
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
@@ -73,14 +70,15 @@ export const actions = {
|
||||
throw new Error(error);
|
||||
}
|
||||
},
|
||||
|
||||
updatePresence: async ({ commit, dispatch }, data) => {
|
||||
commit(types.default.SET_AGENT_UPDATING_STATUS, true);
|
||||
commit(types.default.UPDATE_AGENTS_PRESENCE, data);
|
||||
dispatch('updateReportAgentStatus', data, { root: true });
|
||||
commit(types.default.SET_AGENT_UPDATING_STATUS, false);
|
||||
updateSingleAgentPresence: ({ commit }, { id, availabilityStatus }) => {
|
||||
commit(types.default.UPDATE_SINGLE_AGENT_PRESENCE, {
|
||||
id,
|
||||
availabilityStatus,
|
||||
});
|
||||
},
|
||||
updatePresence: async ({ commit }, data) => {
|
||||
commit(types.default.UPDATE_AGENTS_PRESENCE, data);
|
||||
},
|
||||
|
||||
delete: async ({ commit }, agentId) => {
|
||||
commit(types.default.SET_AGENT_DELETING_STATUS, true);
|
||||
try {
|
||||
@@ -113,6 +111,14 @@ export const mutations = {
|
||||
[types.default.EDIT_AGENT]: MutationHelpers.update,
|
||||
[types.default.DELETE_AGENT]: MutationHelpers.destroy,
|
||||
[types.default.UPDATE_AGENTS_PRESENCE]: MutationHelpers.updatePresence,
|
||||
[types.default.UPDATE_SINGLE_AGENT_PRESENCE]: (
|
||||
$state,
|
||||
{ id, availabilityStatus }
|
||||
) =>
|
||||
MutationHelpers.updateSingleRecordPresence($state.records, {
|
||||
id,
|
||||
availabilityStatus,
|
||||
}),
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
@@ -159,7 +159,10 @@ export const actions = {
|
||||
const userData = response.data;
|
||||
const { id } = userData;
|
||||
commit(types.SET_CURRENT_USER, response.data);
|
||||
dispatch('agents/updatePresence', { [id]: params.availability });
|
||||
dispatch('agents/updateSingleAgentPresence', {
|
||||
id,
|
||||
availabilityStatus: params.availability,
|
||||
});
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
/* eslint no-console: 0 */
|
||||
/* eslint no-param-reassign: 0 */
|
||||
/* eslint no-shadow: 0 */
|
||||
import * as types from '../mutation-types';
|
||||
import Report from '../../api/reports';
|
||||
import Vue from 'vue';
|
||||
|
||||
import { downloadCsvFile } from '../../helper/downloadHelper';
|
||||
|
||||
const state = {
|
||||
@@ -116,9 +112,6 @@ export const actions = {
|
||||
commit(types.default.TOGGLE_AGENT_CONVERSATION_METRIC_LOADING, false);
|
||||
});
|
||||
},
|
||||
updateReportAgentStatus({ commit }, data) {
|
||||
commit(types.default.UPDATE_REPORT_AGENTS_STATUS, data);
|
||||
},
|
||||
downloadAgentReports(_, reportObj) {
|
||||
return Report.getAgentReports(reportObj)
|
||||
.then(response => {
|
||||
@@ -179,16 +172,6 @@ const mutations = {
|
||||
[types.default.TOGGLE_AGENT_CONVERSATION_METRIC_LOADING](_state, flag) {
|
||||
_state.overview.uiFlags.isFetchingAgentConversationMetric = flag;
|
||||
},
|
||||
[types.default.UPDATE_REPORT_AGENTS_STATUS](_state, data) {
|
||||
_state.overview.agentConversationMetric.forEach((element, index) => {
|
||||
const availabilityStatus = data[element.id];
|
||||
Vue.set(
|
||||
_state.overview.agentConversationMetric[index],
|
||||
'availability',
|
||||
availabilityStatus || 'offline'
|
||||
);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
@@ -96,13 +96,21 @@ describe('#actions', () => {
|
||||
});
|
||||
|
||||
describe('#updatePresence', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
it('sends correct actions', async () => {
|
||||
const data = { users: { 1: 'online' }, contacts: { 2: 'online' } };
|
||||
actions.updatePresence({ commit, dispatch }, data);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_AGENT_UPDATING_STATUS, true],
|
||||
[types.default.UPDATE_AGENTS_PRESENCE, data],
|
||||
[types.default.SET_AGENT_UPDATING_STATUS, false],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#updateSingleAgentPresence', () => {
|
||||
it('sends correct actions', async () => {
|
||||
const data = { id: 1, availabilityStatus: 'online' };
|
||||
actions.updateSingleAgentPresence({ commit, dispatch }, data);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.UPDATE_SINGLE_AGENT_PRESENCE, data],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -129,19 +129,4 @@ describe('#getters', () => {
|
||||
offline: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it('getAgentStatus', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Agent 1',
|
||||
email: 'agent1@chatwoot.com',
|
||||
confirmed: true,
|
||||
availability_status: 'online',
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(getters.getAgentsCount(state)).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -97,4 +97,44 @@ describe('#mutations', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#UPDATE_SINGLE_AGENT_PRESENCE', () => {
|
||||
it('updates single agent presence', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Agent1',
|
||||
email: 'agent1@chatwoot.com',
|
||||
availability_status: 'offline',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Agent1',
|
||||
email: 'agent1@chatwoot.com',
|
||||
availability_status: 'online',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
mutations[types.default.UPDATE_SINGLE_AGENT_PRESENCE](state, {
|
||||
id: 1,
|
||||
availabilityStatus: 'busy',
|
||||
});
|
||||
expect(state.records).toEqual([
|
||||
{
|
||||
id: 1,
|
||||
name: 'Agent1',
|
||||
email: 'agent1@chatwoot.com',
|
||||
availability_status: 'busy',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Agent1',
|
||||
email: 'agent1@chatwoot.com',
|
||||
availability_status: 'online',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -80,7 +80,10 @@ describe('#actions', () => {
|
||||
],
|
||||
]);
|
||||
expect(dispatch.mock.calls).toEqual([
|
||||
['agents/updatePresence', { 1: 'offline' }],
|
||||
[
|
||||
'agents/updateSingleAgentPresence',
|
||||
{ availabilityStatus: 'offline', id: 1 },
|
||||
],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user