2021-04-22 17:47:29 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
|
2022-05-23 13:54:07 +00:00
|
|
|
import AssignableAgentsAPI from '../../api/assignableAgents';
|
2021-04-22 17:47:29 +00:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
records: {},
|
|
|
|
uiFlags: {
|
|
|
|
isFetching: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const types = {
|
|
|
|
SET_INBOX_ASSIGNABLE_AGENTS_UI_FLAG: 'SET_INBOX_ASSIGNABLE_AGENTS_UI_FLAG',
|
|
|
|
SET_INBOX_ASSIGNABLE_AGENTS: 'SET_INBOX_ASSIGNABLE_AGENTS',
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getters = {
|
|
|
|
getAssignableAgents: $state => inboxId => {
|
|
|
|
const allAgents = $state.records[inboxId] || [];
|
|
|
|
const verifiedAgents = allAgents.filter(record => record.confirmed);
|
|
|
|
return verifiedAgents;
|
|
|
|
},
|
|
|
|
getUIFlags($state) {
|
|
|
|
return $state.uiFlags;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const actions = {
|
2022-06-03 05:42:22 +00:00
|
|
|
async fetch({ commit }, inboxIds) {
|
2021-04-22 17:47:29 +00:00
|
|
|
commit(types.SET_INBOX_ASSIGNABLE_AGENTS_UI_FLAG, { isFetching: true });
|
|
|
|
try {
|
|
|
|
const {
|
|
|
|
data: { payload },
|
2022-06-03 05:42:22 +00:00
|
|
|
} = await AssignableAgentsAPI.get(inboxIds);
|
|
|
|
commit(types.SET_INBOX_ASSIGNABLE_AGENTS, {
|
|
|
|
inboxId: inboxIds.join(','),
|
|
|
|
members: payload,
|
|
|
|
});
|
2021-04-22 17:47:29 +00:00
|
|
|
} catch (error) {
|
|
|
|
throw new Error(error);
|
|
|
|
} finally {
|
|
|
|
commit(types.SET_INBOX_ASSIGNABLE_AGENTS_UI_FLAG, { isFetching: false });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
[types.SET_INBOX_ASSIGNABLE_AGENTS_UI_FLAG]($state, data) {
|
|
|
|
$state.uiFlags = {
|
|
|
|
...$state.uiFlags,
|
|
|
|
...data,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
[types.SET_INBOX_ASSIGNABLE_AGENTS]: ($state, { inboxId, members }) => {
|
|
|
|
Vue.set($state.records, inboxId, members);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations,
|
|
|
|
};
|