mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-20 21:15:01 +00:00
Fixes https://github.com/chatwoot/chatwoot/issues/8436 Fixes https://github.com/chatwoot/chatwoot/issues/9767 Fixes https://github.com/chatwoot/chatwoot/issues/10156 Fixes https://github.com/chatwoot/chatwoot/issues/6031 Fixes https://github.com/chatwoot/chatwoot/issues/5696 Fixes https://github.com/chatwoot/chatwoot/issues/9250 Fixes https://github.com/chatwoot/chatwoot/issues/9762 --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
import { getAvailableAgents } from 'widget/api/agent';
|
|
import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
|
|
|
|
const state = {
|
|
records: [],
|
|
uiFlags: {
|
|
isError: false,
|
|
hasFetched: false,
|
|
},
|
|
};
|
|
|
|
export const getters = {
|
|
getHasFetched: $state => $state.uiFlags.hasFetched,
|
|
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);
|
|
}
|
|
},
|
|
updatePresence: async ({ commit }, data) => {
|
|
commit('updatePresence', data);
|
|
},
|
|
};
|
|
|
|
export const mutations = {
|
|
setAgents($state, data) {
|
|
$state.records = data;
|
|
},
|
|
updatePresence: MutationHelpers.updatePresence,
|
|
setError($state, value) {
|
|
$state.uiFlags.isError = value;
|
|
},
|
|
setHasFetched($state, value) {
|
|
$state.uiFlags.hasFetched = value;
|
|
},
|
|
};
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state,
|
|
getters,
|
|
actions,
|
|
mutations,
|
|
};
|