Feature: Availability Statuses (#874)

Co-authored-by: Pranav Raj S <pranav@thoughtwoot.com>
This commit is contained in:
Sojan Jose
2020-07-04 11:42:47 +05:30
committed by GitHub
parent bd87927576
commit c98907db49
35 changed files with 413 additions and 77 deletions

View File

@@ -57,6 +57,13 @@ export const actions = {
throw new Error(error);
}
},
updatePresence: async ({ commit }, data) => {
commit(types.default.SET_AGENT_UPDATING_STATUS, true);
commit(types.default.UPDATE_AGENTS_PRESENCE, data);
commit(types.default.SET_AGENT_UPDATING_STATUS, false);
},
delete: async ({ commit }, agentId) => {
commit(types.default.SET_AGENT_DELETING_STATUS, true);
try {
@@ -88,6 +95,7 @@ export const mutations = {
[types.default.ADD_AGENT]: MutationHelpers.create,
[types.default.EDIT_AGENT]: MutationHelpers.update,
[types.default.DELETE_AGENT]: MutationHelpers.destroy,
[types.default.UPDATE_AGENTS_PRESENCE]: MutationHelpers.updatePresence,
};
export default {

View File

@@ -59,6 +59,10 @@ export const actions = {
throw new Error(error);
}
},
updatePresence: ({ commit }, data) => {
commit(types.default.UPDATE_CONTACTS_PRESENCE, data);
},
};
export const mutations = {
@@ -88,6 +92,21 @@ export const mutations = {
[types.default.EDIT_CONTACT]: ($state, data) => {
Vue.set($state.records, data.id, data);
},
[types.default.UPDATE_CONTACTS_PRESENCE]: ($state, data) => {
Object.values($state.records).forEach(element => {
const availabilityStatus = data[element.id];
if (availabilityStatus) {
Vue.set(
$state.records[element.id],
'availability_status',
availabilityStatus
);
} else {
Vue.delete($state.records[element.id], 'availability_status');
}
});
},
};
export default {

View File

@@ -93,4 +93,16 @@ describe('#actions', () => {
]);
});
});
describe('#updatePresence', () => {
it('sends correct actions if API is success', async () => {
const data = { users: { 1: 'online' }, contacts: { 2: 'online' } };
actions.updatePresence({ commit }, 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],
]);
});
});
});

View File

@@ -60,4 +60,40 @@ describe('#mutations', () => {
expect(state.records).toEqual([]);
});
});
describe('#UPDATE_AGENTS_PRESENCE', () => {
it('updates 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_AGENTS_PRESENCE](state, { '1': 'busy' });
expect(state.records).toEqual([
{
id: 1,
name: 'Agent1',
email: 'agent1@chatwoot.com',
availability_status: 'busy',
},
{
id: 2,
name: 'Agent1',
email: 'agent1@chatwoot.com',
},
]);
});
});
});