mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-18 20:15:10 +00:00
feat: Add Integration hooks UI (#2301)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
/* eslint no-param-reassign: 0 */
|
||||
import Vue from 'vue';
|
||||
import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
|
||||
import * as types from '../mutation-types';
|
||||
import IntegrationsAPI from '../../api/integrations';
|
||||
@@ -6,15 +7,23 @@ import IntegrationsAPI from '../../api/integrations';
|
||||
const state = {
|
||||
records: [],
|
||||
uiFlags: {
|
||||
isCreating: false,
|
||||
isFetching: false,
|
||||
isFetchingItem: false,
|
||||
isUpdating: false,
|
||||
isCreatingHook: false,
|
||||
isDeletingHook: false,
|
||||
},
|
||||
};
|
||||
|
||||
export const getters = {
|
||||
getIntegrations($state) {
|
||||
return $state.records;
|
||||
return $state.records.filter(
|
||||
item => item.id !== 'fullcontact' && item.id !== 'dialogflow'
|
||||
);
|
||||
},
|
||||
getAppIntegrations($state) {
|
||||
return $state.records.filter(item => item.id === 'dialogflow');
|
||||
},
|
||||
getIntegration: $state => integrationId => {
|
||||
const [integration] = $state.records.filter(
|
||||
@@ -63,6 +72,28 @@ export const actions = {
|
||||
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isDeleting: false });
|
||||
}
|
||||
},
|
||||
createHook: async ({ commit }, hookData) => {
|
||||
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isCreatingHook: true });
|
||||
try {
|
||||
const response = await IntegrationsAPI.createHook(hookData);
|
||||
commit(types.default.ADD_INTEGRATION_HOOKS, response.data);
|
||||
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isCreatingHook: false });
|
||||
} catch (error) {
|
||||
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isCreatingHook: false });
|
||||
throw new Error(error);
|
||||
}
|
||||
},
|
||||
deleteHook: async ({ commit }, { appId, hookId }) => {
|
||||
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isDeletingHook: true });
|
||||
try {
|
||||
await IntegrationsAPI.deleteHook(hookId);
|
||||
commit(types.default.DELETE_INTEGRATION_HOOKS, { appId, hookId });
|
||||
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isDeletingHook: false });
|
||||
} catch (error) {
|
||||
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isDeletingHook: false });
|
||||
throw new Error(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
@@ -72,6 +103,25 @@ export const mutations = {
|
||||
[types.default.SET_INTEGRATIONS]: MutationHelpers.set,
|
||||
[types.default.ADD_INTEGRATION]: MutationHelpers.updateAttributes,
|
||||
[types.default.DELETE_INTEGRATION]: MutationHelpers.updateAttributes,
|
||||
[types.default.ADD_INTEGRATION_HOOKS]: ($state, data) => {
|
||||
$state.records.forEach((element, index) => {
|
||||
if (element.id === data.app_id) {
|
||||
const record = $state.records[index];
|
||||
Vue.set(record, 'hooks', [...record.hooks, data]);
|
||||
}
|
||||
});
|
||||
},
|
||||
[types.default.DELETE_INTEGRATION_HOOKS]: ($state, { appId, hookId }) => {
|
||||
$state.records.forEach((element, index) => {
|
||||
if (element.id === appId) {
|
||||
const record = $state.records[index];
|
||||
const hooksWithoutDeletedHook = record.hooks.filter(
|
||||
hook => hook.id !== hookId
|
||||
);
|
||||
Vue.set(record, 'hooks', hooksWithoutDeletedHook);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
Reference in New Issue
Block a user