refactor: optimize agent bot assignment dropdown (#14866)
This commit is contained in:
@@ -7,31 +7,52 @@ const state = {
|
||||
},
|
||||
};
|
||||
|
||||
const recordKey = (inboxId, { includeAgentBots = false } = {}) =>
|
||||
includeAgentBots ? `${inboxId}:with_agent_bots` : inboxId;
|
||||
|
||||
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;
|
||||
},
|
||||
getAssignableAgents:
|
||||
$state =>
|
||||
(inboxId, options = {}) => {
|
||||
const includeAgentBots = options.includeAgentBots || false;
|
||||
const allAgents = $state.records[recordKey(inboxId, options)] || [];
|
||||
const verifiedAgents = allAgents.filter(
|
||||
record =>
|
||||
record.confirmed ||
|
||||
(includeAgentBots && record.assignee_type === 'AgentBot')
|
||||
);
|
||||
return verifiedAgents;
|
||||
},
|
||||
getUIFlags($state) {
|
||||
return $state.uiFlags;
|
||||
},
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
async fetch({ commit }, inboxIds) {
|
||||
async fetch({ commit }, actionPayload) {
|
||||
const inboxIds = Array.isArray(actionPayload)
|
||||
? actionPayload
|
||||
: actionPayload.inboxIds;
|
||||
const includeAgentBots =
|
||||
!Array.isArray(actionPayload) && actionPayload.includeAgentBots;
|
||||
commit(types.SET_INBOX_ASSIGNABLE_AGENTS_UI_FLAG, { isFetching: true });
|
||||
try {
|
||||
const {
|
||||
data: { payload },
|
||||
} = await AssignableAgentsAPI.get(inboxIds);
|
||||
} = await AssignableAgentsAPI.get(inboxIds, { includeAgentBots });
|
||||
if (includeAgentBots) {
|
||||
commit(types.SET_INBOX_ASSIGNABLE_AGENTS, {
|
||||
inboxId: inboxIds.join(','),
|
||||
members: payload,
|
||||
});
|
||||
}
|
||||
commit(types.SET_INBOX_ASSIGNABLE_AGENTS, {
|
||||
inboxId: inboxIds.join(','),
|
||||
inboxId: recordKey(inboxIds.join(','), { includeAgentBots }),
|
||||
members: payload,
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user