From 30a79fdde1edafddb4e2d84fca68e2ef1cc35fba Mon Sep 17 00:00:00 2001 From: lizacoma Date: Fri, 22 Mar 2024 22:19:56 +0200 Subject: [PATCH 1/8] feature: new tab in teams in progress [WTEL-4246] --- .../modules/teams/components/opened-team.vue | 6 + .../teams/modules/hooks/api/teamHooks.js | 167 ++++++++++++++++++ .../components/opened-team-hooks-popup.vue | 105 +++++++++++ .../hooks/components/opened-team-hooks.vue | 112 ++++++++++++ .../modules/hooks/enum/HookEvent.enum.js | 10 ++ .../modules/hooks/store/_internals/headers.js | 23 +++ .../teams/modules/hooks/store/team-hooks.js | 20 +++ .../modules/teams/store/teams.js | 3 +- 8 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 src/modules/contact-center/modules/teams/modules/hooks/api/teamHooks.js create mode 100644 src/modules/contact-center/modules/teams/modules/hooks/components/opened-team-hooks-popup.vue create mode 100644 src/modules/contact-center/modules/teams/modules/hooks/components/opened-team-hooks.vue create mode 100644 src/modules/contact-center/modules/teams/modules/hooks/enum/HookEvent.enum.js create mode 100644 src/modules/contact-center/modules/teams/modules/hooks/store/_internals/headers.js create mode 100644 src/modules/contact-center/modules/teams/modules/hooks/store/team-hooks.js diff --git a/src/modules/contact-center/modules/teams/components/opened-team.vue b/src/modules/contact-center/modules/teams/components/opened-team.vue index b6d438017..668b1654e 100644 --- a/src/modules/contact-center/modules/teams/components/opened-team.vue +++ b/src/modules/contact-center/modules/teams/components/opened-team.vue @@ -42,6 +42,7 @@ import Agents from '../modules/agents/components/opened-team-agents.vue'; import Supervisors from '../modules/supervisors/components/opened-team-supervisors.vue'; import General from './opened-team-general.vue'; import Parameters from './opened-team-parameters.vue'; +import Hooks from '../modules/hooks/components/opened-team-hooks.vue'; export default { name: 'OpenedTeam', @@ -50,6 +51,7 @@ export default { Supervisors, Agents, Parameters, + Hooks, }, mixins: [openedObjectMixin], @@ -88,6 +90,10 @@ export default { text: this.$tc('objects.ccenter.agents.agents', 2), value: 'agents', }, + { + text: this.$tc('objects.ccenter.queues.hooks.hooks', 2), + value: 'hooks', + } ]; if (this.id) tabs.push(this.permissionsTab); diff --git a/src/modules/contact-center/modules/teams/modules/hooks/api/teamHooks.js b/src/modules/contact-center/modules/teams/modules/hooks/api/teamHooks.js new file mode 100644 index 000000000..5e1f15a1a --- /dev/null +++ b/src/modules/contact-center/modules/teams/modules/hooks/api/teamHooks.js @@ -0,0 +1,167 @@ +import { + getDefaultGetListResponse, + getDefaultGetParams, +} from '@webitel/ui-sdk/src/api/defaults'; +import applyTransform, { + camelToSnake, + merge, + mergeEach, + notify, + sanitize, + snakeToCamel, + starToSearch, +} from '@webitel/ui-sdk/src/api/transformers'; +import { TeamHookServiceApi } from 'webitel-sdk'; +import instance from '../../../../../../../app/api/instance'; +import configuration from '../../../../../../../app/api/openAPIConfig'; + +const teamHookService = new TeamHookServiceApi(configuration, '', instance); + +const fieldsToSend = ['event', 'properties', 'schema', 'enabled']; + +const preRequestHandler = (parentId) => (item) => ({ + ...item, + teamId: parentId, +}); + +const getTeamHooksList = async (params) => { + const defaultObject = { + enabled: false, + }; + + const { + page, + size, + search, + sort, + fields, + id, + parentId, + } = applyTransform(params, [ + merge(getDefaultGetParams()), + starToSearch('search'), + ]); + + try { + const response = await teamHookService.searchTeamHook( + parentId, + page, + size, + search, + sort, + fields, + id, + ); + const { items, next } = applyTransform(response.data, [ + snakeToCamel(), + merge(getDefaultGetListResponse()), + ]); + return { + items: applyTransform(items, [ + mergeEach(defaultObject), + ]), + next, + }; + } catch (err) { + throw applyTransform(err, [ + notify, + ]); + } +}; + +const getTeamHook = async ({ parentId, itemId: id }) => { + const defaultObject = { + event: '', + properties: [], + schema: {}, + enabled: false, + }; + + try { + const response = await teamHookService.readTeamHook(parentId, id); + return applyTransform(response.data, [ + snakeToCamel(), + merge(defaultObject), + ]); + } catch (err) { + throw applyTransform(err, [ + notify, + ]); + } +}; + +const addTeamHook = async ({ parentId, itemInstance }) => { + const item = applyTransform(itemInstance, [ + preRequestHandler(parentId), + sanitize(fieldsToSend), + camelToSnake(), + ]); + try { + const response = await teamHookService.createTeamHook(parentId, item); + return applyTransform(response.data, [ + snakeToCamel(), + ]); + } catch (err) { + throw applyTransform(err, [ + notify, + ]); + } +}; + +const patchTeamHook = async ({ changes, id, parentId }) => { + const body = applyTransform(changes, [ + sanitize(fieldsToSend), + camelToSnake(), + ]); + + try { + const response = await teamHookService.patchTeamHook(parentId, id, body); + return applyTransform(response.data, [ + snakeToCamel(), + ]); + } catch (err) { + throw applyTransform(err, [ + notify, + ]); + } +}; + +const updateTeamHook = async ({ itemInstance, itemId: id, parentId }) => { + const item = applyTransform(itemInstance, [ + preRequestHandler(parentId), + sanitize(fieldsToSend), + camelToSnake(), + ]); + try { + const response = await teamHookService.updateTeamHook(parentId, id, item); + return applyTransform(response.data, [ + snakeToCamel(), + ]); + } catch (err) { + throw applyTransform(err, [ + notify, + ]); + } +}; + +const deleteTeamHook = async ({ parentId, id }) => { + try { + const response = await teamHookService.deleteTeamHook(parentId, id); + return applyTransform(response.data, []); + } catch (err) { + throw applyTransform(err, [ + notify, + ]); + } +}; + +const TeamHooksAPI = { + getList: getTeamHooksList, + get: getTeamHook, + add: addTeamHook, + patch: patchTeamHook, + update: updateTeamHook, + delete: deleteTeamHook, +}; + +export default TeamHooksAPI; diff --git a/src/modules/contact-center/modules/teams/modules/hooks/components/opened-team-hooks-popup.vue b/src/modules/contact-center/modules/teams/modules/hooks/components/opened-team-hooks-popup.vue new file mode 100644 index 000000000..79683888c --- /dev/null +++ b/src/modules/contact-center/modules/teams/modules/hooks/components/opened-team-hooks-popup.vue @@ -0,0 +1,105 @@ + + + + + diff --git a/src/modules/contact-center/modules/teams/modules/hooks/components/opened-team-hooks.vue b/src/modules/contact-center/modules/teams/modules/hooks/components/opened-team-hooks.vue new file mode 100644 index 000000000..d608b018d --- /dev/null +++ b/src/modules/contact-center/modules/teams/modules/hooks/components/opened-team-hooks.vue @@ -0,0 +1,112 @@ + + + + + diff --git a/src/modules/contact-center/modules/teams/modules/hooks/enum/HookEvent.enum.js b/src/modules/contact-center/modules/teams/modules/hooks/enum/HookEvent.enum.js new file mode 100644 index 000000000..ef068b580 --- /dev/null +++ b/src/modules/contact-center/modules/teams/modules/hooks/enum/HookEvent.enum.js @@ -0,0 +1,10 @@ +export default Object.freeze({ + JOINED: 'joined', + ANSWERED: 'answered', + OFFERING: 'offering', + BRIDGED: 'bridged', + MISSED: 'missed', + LEAVING: 'leaving', + PROCESSING: 'processing', + ACTIVE: 'active', +}); diff --git a/src/modules/contact-center/modules/teams/modules/hooks/store/_internals/headers.js b/src/modules/contact-center/modules/teams/modules/hooks/store/_internals/headers.js new file mode 100644 index 000000000..72ce3f8aa --- /dev/null +++ b/src/modules/contact-center/modules/teams/modules/hooks/store/_internals/headers.js @@ -0,0 +1,23 @@ +import { SortSymbols } from '@webitel/ui-sdk/src/scripts/sortQueryAdapters'; + +export default [ + { + value: 'event', + locale: 'objects.ccenter.queues.hooks.event', + field: 'event', + sort: SortSymbols.NONE, + }, + { + value: 'schema', + locale: ['objects.routing.flow.flow', 1], + field: 'schema', + sort: SortSymbols.NONE, + }, + { + value: 'state', + locale: 'reusable.state', + field: 'enabled', + width: '100px', + sort: SortSymbols.NONE, + }, +]; diff --git a/src/modules/contact-center/modules/teams/modules/hooks/store/team-hooks.js b/src/modules/contact-center/modules/teams/modules/hooks/store/team-hooks.js new file mode 100644 index 000000000..d0f455a59 --- /dev/null +++ b/src/modules/contact-center/modules/teams/modules/hooks/store/team-hooks.js @@ -0,0 +1,20 @@ +import NestedObjectStoreModule + from '../../../../../../../app/store/BaseStoreModules/StoreModules/NestedObjectStoreModule'; +import TeamHooksAPI from '../api/teamHooks'; +import headers from './_internals/headers'; + +const resettableItemState = { + itemInstance: { + event: '', + properties: [], + schema: {}, + enabled: true, + }, +}; + +const teamHooks = new NestedObjectStoreModule({ resettableItemState, headers }) + .attachAPIModule(TeamHooksAPI) + .generateAPIActions() + .getModule(); + +export default teamHooks; diff --git a/src/modules/contact-center/modules/teams/store/teams.js b/src/modules/contact-center/modules/teams/store/teams.js index 4135da601..59af9fc11 100644 --- a/src/modules/contact-center/modules/teams/store/teams.js +++ b/src/modules/contact-center/modules/teams/store/teams.js @@ -5,6 +5,7 @@ import PermissionsStoreModule import TeamsAPI from '../api/teams'; import agents from '../modules/agents/store/team-agents'; import supervisors from '../modules/supervisors/store/team-supervisors'; +import hooks from '../modules/hooks/store/team-hooks'; import headers from './_internals/headers'; const resettableState = { @@ -38,7 +39,7 @@ const permissions = new PermissionsStoreModule() const teams = new ObjectStoreModule({ resettableState, headers }) .attachAPIModule(TeamsAPI) .generateAPIActions() -.setChildModules({ supervisors, agents, permissions }) +.setChildModules({ supervisors, agents, hooks, permissions }) .getModule({ actions }); export default teams; From 34dbe3e898e3b3113203c00b8ac3afabef839918 Mon Sep 17 00:00:00 2001 From: lizacoma Date: Tue, 26 Mar 2024 15:15:36 +0200 Subject: [PATCH 2/8] feature: added tab hook in teams [WTEL-4246] --- .../modules/teams/components/opened-team.vue | 3 +-- .../modules/teams/modules/hooks/api/teamHooks.js | 6 ++++-- .../modules/hooks/components/opened-team-hooks-popup.vue | 6 +++--- .../teams/modules/hooks/components/opened-team-hooks.vue | 6 +++--- .../modules/teams/modules/hooks/enum/HookEvent.enum.js | 9 +-------- .../teams/modules/supervisors/api/teamSupervisors.js | 3 ++- src/modules/contact-center/modules/teams/store/teams.js | 3 ++- 7 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/modules/contact-center/modules/teams/components/opened-team.vue b/src/modules/contact-center/modules/teams/components/opened-team.vue index 668b1654e..961f7b596 100644 --- a/src/modules/contact-center/modules/teams/components/opened-team.vue +++ b/src/modules/contact-center/modules/teams/components/opened-team.vue @@ -89,8 +89,7 @@ export default { }, { text: this.$tc('objects.ccenter.agents.agents', 2), value: 'agents', - }, - { + }, { text: this.$tc('objects.ccenter.queues.hooks.hooks', 2), value: 'hooks', } diff --git a/src/modules/contact-center/modules/teams/modules/hooks/api/teamHooks.js b/src/modules/contact-center/modules/teams/modules/hooks/api/teamHooks.js index 5e1f15a1a..f47a44c36 100644 --- a/src/modules/contact-center/modules/teams/modules/hooks/api/teamHooks.js +++ b/src/modules/contact-center/modules/teams/modules/hooks/api/teamHooks.js @@ -11,11 +11,11 @@ import applyTransform, { snakeToCamel, starToSearch, } from '@webitel/ui-sdk/src/api/transformers'; -import { TeamHookServiceApi } from 'webitel-sdk'; +import { TeamHookServiceApiFactory } from 'webitel-sdk'; import instance from '../../../../../../../app/api/instance'; import configuration from '../../../../../../../app/api/openAPIConfig'; -const teamHookService = new TeamHookServiceApi(configuration, '', instance); +const teamHookService = new TeamHookServiceApiFactory(configuration, '', instance); const fieldsToSend = ['event', 'properties', 'schema', 'enabled']; @@ -52,6 +52,7 @@ const getTeamHooksList = async (params) => { fields, id, ); + console.log('getTeamHooksList'); const { items, next } = applyTransform(response.data, [ snakeToCamel(), merge(getDefaultGetListResponse()), @@ -97,6 +98,7 @@ const addTeamHook = async ({ parentId, itemInstance }) => { camelToSnake(), ]); try { + console.log('addTeamHook item', item); const response = await teamHookService.createTeamHook(parentId, item); return applyTransform(response.data, [ snakeToCamel(), diff --git a/src/modules/contact-center/modules/teams/modules/hooks/components/opened-team-hooks-popup.vue b/src/modules/contact-center/modules/teams/modules/hooks/components/opened-team-hooks-popup.vue index 79683888c..de855a92e 100644 --- a/src/modules/contact-center/modules/teams/modules/hooks/components/opened-team-hooks-popup.vue +++ b/src/modules/contact-center/modules/teams/modules/hooks/components/opened-team-hooks-popup.vue @@ -5,7 +5,7 @@ @close="close" >