2020-02-05 05:57:22 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import { getAvailableAgents } from 'widget/api/agent';
|
2020-07-04 06:12:47 +00:00
|
|
|
import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
|
2020-02-05 05:57:22 +00:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
records: [],
|
|
|
|
uiFlags: {
|
|
|
|
isError: false,
|
|
|
|
hasFetched: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getters = {
|
2020-07-07 18:34:44 +00:00
|
|
|
getHasFetched: $state => $state.uiFlags.hasFetched,
|
2020-02-05 05:57:22 +00:00
|
|
|
availableAgents: $state =>
|
|
|
|
$state.records.filter(agent => agent.availability_status === 'online'),
|
|
|
|
};
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
fetchAvailableAgents: async ({ commit }, websiteToken) => {
|
|
|
|
try {
|
|
|
|
const { data } = await getAvailableAgents(websiteToken);
|
|
|
|
const { payload = [] } = data;
|
|
|
|
commit('setAgents', payload);
|
|
|
|
commit('setError', false);
|
|
|
|
commit('setHasFetched', true);
|
|
|
|
} catch (error) {
|
|
|
|
commit('setError', true);
|
|
|
|
commit('setHasFetched', true);
|
|
|
|
}
|
|
|
|
},
|
2020-07-04 06:12:47 +00:00
|
|
|
updatePresence: async ({ commit }, data) => {
|
|
|
|
commit('updatePresence', data);
|
|
|
|
},
|
2020-02-05 05:57:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
setAgents($state, data) {
|
|
|
|
Vue.set($state, 'records', data);
|
|
|
|
},
|
2020-07-04 06:12:47 +00:00
|
|
|
updatePresence: MutationHelpers.updatePresence,
|
2020-02-05 05:57:22 +00:00
|
|
|
setError($state, value) {
|
|
|
|
Vue.set($state.uiFlags, 'isError', value);
|
|
|
|
},
|
|
|
|
setHasFetched($state, value) {
|
|
|
|
Vue.set($state.uiFlags, 'hasFetched', value);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations,
|
|
|
|
};
|