chore: Allow admins to choose the agent bot from the UI (#5895)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import Vue from 'vue';
|
||||
import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
|
||||
import types from '../mutation-types';
|
||||
import AgentBotsAPI from '../../api/agentBots';
|
||||
import InboxesAPI from '../../api/inboxes';
|
||||
import { throwErrorMessage } from '../utils/api';
|
||||
|
||||
export const state = {
|
||||
@@ -11,7 +13,10 @@ export const state = {
|
||||
isCreating: false,
|
||||
isDeleting: false,
|
||||
isUpdating: false,
|
||||
isFetchingAgentBot: false,
|
||||
isSettingAgentBot: false,
|
||||
},
|
||||
agentBotInbox: {},
|
||||
};
|
||||
|
||||
export const getters = {
|
||||
@@ -25,6 +30,10 @@ export const getters = {
|
||||
const [bot] = $state.records.filter(record => record.id === Number(botId));
|
||||
return bot || {};
|
||||
},
|
||||
getActiveAgentBot: $state => inboxId => {
|
||||
const associatedAgentBotId = $state.agentBotInbox[Number(inboxId)];
|
||||
return getters.getBot($state)(associatedAgentBotId);
|
||||
},
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
@@ -85,6 +94,31 @@ export const actions = {
|
||||
commit(types.SET_AGENT_BOT_UI_FLAG, { isFetchingItem: false });
|
||||
}
|
||||
},
|
||||
|
||||
fetchAgentBotInbox: async ({ commit }, inboxId) => {
|
||||
commit(types.SET_AGENT_BOT_UI_FLAG, { isFetchingAgentBot: true });
|
||||
try {
|
||||
const { data } = await InboxesAPI.getAgentBot(inboxId);
|
||||
const { agent_bot: agentBot = {} } = data || {};
|
||||
commit(types.SET_AGENT_BOT_INBOX, { agentBotId: agentBot.id, inboxId });
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
} finally {
|
||||
commit(types.SET_AGENT_BOT_UI_FLAG, { isFetchingAgentBot: false });
|
||||
}
|
||||
},
|
||||
|
||||
setAgentBotInbox: async ({ commit }, { inboxId, botId }) => {
|
||||
commit(types.SET_AGENT_BOT_UI_FLAG, { isSettingAgentBot: true });
|
||||
try {
|
||||
await InboxesAPI.setAgentBot(inboxId, botId);
|
||||
commit(types.SET_AGENT_BOT_INBOX, { agentBotId: botId, inboxId });
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
} finally {
|
||||
commit(types.SET_AGENT_BOT_UI_FLAG, { isSettingAgentBot: false });
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
@@ -98,6 +132,9 @@ export const mutations = {
|
||||
[types.SET_AGENT_BOTS]: MutationHelpers.set,
|
||||
[types.EDIT_AGENT_BOT]: MutationHelpers.update,
|
||||
[types.DELETE_AGENT_BOT]: MutationHelpers.destroy,
|
||||
[types.SET_AGENT_BOT_INBOX]($state, { agentBotId, inboxId }) {
|
||||
Vue.set($state.agentBotInbox, inboxId, agentBotId);
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
Reference in New Issue
Block a user