2019-12-21 17:24:35 +00:00
|
|
|
import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
|
|
|
|
import * as types from '../mutation-types';
|
|
|
|
import AgentAPI from '../../api/agents';
|
|
|
|
|
|
|
|
export const state = {
|
|
|
|
records: [],
|
|
|
|
uiFlags: {
|
|
|
|
isFetching: false,
|
|
|
|
isCreating: false,
|
|
|
|
isUpdating: false,
|
|
|
|
isDeleting: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getters = {
|
|
|
|
getAgents($state) {
|
|
|
|
return $state.records;
|
|
|
|
},
|
|
|
|
getVerifiedAgents($state) {
|
|
|
|
return $state.records.filter(record => record.confirmed);
|
|
|
|
},
|
|
|
|
getUIFlags($state) {
|
|
|
|
return $state.uiFlags;
|
|
|
|
},
|
2022-04-25 14:34:41 +00:00
|
|
|
getAgentStatus($state) {
|
|
|
|
let status = {
|
|
|
|
online: $state.records.filter(
|
|
|
|
agent => agent.availability_status === 'online'
|
|
|
|
).length,
|
|
|
|
busy: $state.records.filter(agent => agent.availability_status === 'busy')
|
|
|
|
.length,
|
|
|
|
offline: $state.records.filter(
|
|
|
|
agent => agent.availability_status === 'offline'
|
|
|
|
).length,
|
|
|
|
};
|
|
|
|
return status;
|
|
|
|
},
|
|
|
|
getAgentsCount($state) {
|
|
|
|
return $state.records.length;
|
|
|
|
},
|
2019-12-21 17:24:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
get: async ({ commit }) => {
|
|
|
|
commit(types.default.SET_AGENT_FETCHING_STATUS, true);
|
|
|
|
try {
|
|
|
|
const response = await AgentAPI.get();
|
|
|
|
commit(types.default.SET_AGENT_FETCHING_STATUS, false);
|
|
|
|
commit(types.default.SET_AGENTS, response.data);
|
|
|
|
} catch (error) {
|
|
|
|
commit(types.default.SET_AGENT_FETCHING_STATUS, false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
create: async ({ commit }, agentInfo) => {
|
|
|
|
commit(types.default.SET_AGENT_CREATING_STATUS, true);
|
|
|
|
try {
|
|
|
|
const response = await AgentAPI.create(agentInfo);
|
|
|
|
commit(types.default.ADD_AGENT, response.data);
|
|
|
|
commit(types.default.SET_AGENT_CREATING_STATUS, false);
|
|
|
|
} catch (error) {
|
|
|
|
commit(types.default.SET_AGENT_CREATING_STATUS, false);
|
2020-02-22 13:36:16 +00:00
|
|
|
throw error;
|
2019-12-21 17:24:35 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
update: async ({ commit }, { id, ...agentParams }) => {
|
|
|
|
commit(types.default.SET_AGENT_UPDATING_STATUS, true);
|
|
|
|
try {
|
|
|
|
const response = await AgentAPI.update(id, agentParams);
|
|
|
|
commit(types.default.EDIT_AGENT, response.data);
|
|
|
|
commit(types.default.SET_AGENT_UPDATING_STATUS, false);
|
|
|
|
} catch (error) {
|
|
|
|
commit(types.default.SET_AGENT_UPDATING_STATUS, false);
|
|
|
|
throw new Error(error);
|
|
|
|
}
|
|
|
|
},
|
2020-07-04 06:12:47 +00:00
|
|
|
|
2022-04-25 14:34:41 +00:00
|
|
|
updatePresence: async ({ commit, dispatch }, data) => {
|
2020-07-04 06:12:47 +00:00
|
|
|
commit(types.default.SET_AGENT_UPDATING_STATUS, true);
|
|
|
|
commit(types.default.UPDATE_AGENTS_PRESENCE, data);
|
2022-04-25 14:34:41 +00:00
|
|
|
dispatch('updateReportAgentStatus', data, { root: true });
|
2020-07-04 06:12:47 +00:00
|
|
|
commit(types.default.SET_AGENT_UPDATING_STATUS, false);
|
|
|
|
},
|
|
|
|
|
2019-12-21 17:24:35 +00:00
|
|
|
delete: async ({ commit }, agentId) => {
|
|
|
|
commit(types.default.SET_AGENT_DELETING_STATUS, true);
|
|
|
|
try {
|
|
|
|
await AgentAPI.delete(agentId);
|
|
|
|
commit(types.default.DELETE_AGENT, agentId);
|
|
|
|
commit(types.default.SET_AGENT_DELETING_STATUS, false);
|
|
|
|
} catch (error) {
|
|
|
|
commit(types.default.SET_AGENT_DELETING_STATUS, false);
|
|
|
|
throw new Error(error);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
[types.default.SET_AGENT_FETCHING_STATUS]($state, status) {
|
|
|
|
$state.uiFlags.isFetching = status;
|
|
|
|
},
|
|
|
|
[types.default.SET_AGENT_CREATING_STATUS]($state, status) {
|
|
|
|
$state.uiFlags.isCreating = status;
|
|
|
|
},
|
|
|
|
[types.default.SET_AGENT_UPDATING_STATUS]($state, status) {
|
|
|
|
$state.uiFlags.isUpdating = status;
|
|
|
|
},
|
|
|
|
[types.default.SET_AGENT_DELETING_STATUS]($state, status) {
|
|
|
|
$state.uiFlags.isDeleting = status;
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.default.SET_AGENTS]: MutationHelpers.set,
|
|
|
|
[types.default.ADD_AGENT]: MutationHelpers.create,
|
|
|
|
[types.default.EDIT_AGENT]: MutationHelpers.update,
|
|
|
|
[types.default.DELETE_AGENT]: MutationHelpers.destroy,
|
2020-07-04 06:12:47 +00:00
|
|
|
[types.default.UPDATE_AGENTS_PRESENCE]: MutationHelpers.updatePresence,
|
2019-12-21 17:24:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations,
|
|
|
|
};
|