From 804652e1e6d7810cdff51fdd4450c1a5e609a7e8 Mon Sep 17 00:00:00 2001 From: Lera24 Date: Fri, 27 Sep 2024 15:54:11 +0300 Subject: [PATCH] feature: add pause template page[WTEL-5080] --- src/app/locale/en/en.js | 5 + src/app/locale/ru/ru.js | 5 + src/app/locale/ua/ua.js | 5 + .../_internals/NavigationPages.lookup.js | 5 + src/app/router/_internals/RouteNames.enum.js | 1 + src/app/router/router.js | 5 +- .../agent-pause-cause/api/agentPauseCause.js | 7 + .../pause-templates/api/pauseTemplates.js | 121 ++++++++++++ .../opened-pause-template-causes.vue | 99 ++++++++++ .../opened-pause-template-general.vue | 36 ++++ .../components/opened-pause-template.vue | 113 ++++++++++++ .../components/the-pause-templates.vue | 174 ++++++++++++++++++ .../PauseTemplatesRouteNames.enum.js | 6 + .../pause-templates/router/pauseTemplates.js | 42 +++++ .../store/_internals/headers.js | 16 ++ .../pause-templates/store/pause-templates.js | 42 +++++ src/modules/lookups/store/lookups.js | 2 + 17 files changed, 683 insertions(+), 1 deletion(-) create mode 100644 src/modules/lookups/modules/pause-templates/api/pauseTemplates.js create mode 100644 src/modules/lookups/modules/pause-templates/components/opened-pause-template-causes.vue create mode 100644 src/modules/lookups/modules/pause-templates/components/opened-pause-template-general.vue create mode 100644 src/modules/lookups/modules/pause-templates/components/opened-pause-template.vue create mode 100644 src/modules/lookups/modules/pause-templates/components/the-pause-templates.vue create mode 100644 src/modules/lookups/modules/pause-templates/router/_internals/PauseTemplatesRouteNames.enum.js create mode 100644 src/modules/lookups/modules/pause-templates/router/pauseTemplates.js create mode 100644 src/modules/lookups/modules/pause-templates/store/_internals/headers.js create mode 100644 src/modules/lookups/modules/pause-templates/store/pause-templates.js diff --git a/src/app/locale/en/en.js b/src/app/locale/en/en.js index 4731bbeab..d9b127547 100644 --- a/src/app/locale/en/en.js +++ b/src/app/locale/en/en.js @@ -470,6 +470,11 @@ export default { shiftTemplates: 'Shift template | Shift templates', duration: 'Duration (hh:mm)', }, + pauseTemplates: { + pauseTemplates: 'Pause templates', + pauseReason: 'Pause reason', + duration: 'Duration (mm)', + }, }, routing: { routing: 'Routing', diff --git a/src/app/locale/ru/ru.js b/src/app/locale/ru/ru.js index 43294ca9a..963a2fcea 100644 --- a/src/app/locale/ru/ru.js +++ b/src/app/locale/ru/ru.js @@ -476,6 +476,11 @@ export default { shiftTemplates: 'Шаблон смен | Шаблоны смен', duration: 'Длительность (чч:мм)', }, + pauseTemplates: { + pauseTemplates: 'Шаблоны пауз', + pauseReason: 'Причина паузы', + duration: 'Длительность (мм)', + }, }, routing: { routing: 'Маршрутизация', diff --git a/src/app/locale/ua/ua.js b/src/app/locale/ua/ua.js index 04fa6dafc..23faf1366 100644 --- a/src/app/locale/ua/ua.js +++ b/src/app/locale/ua/ua.js @@ -471,6 +471,11 @@ export default { shiftTemplates: 'Шаблон змін | Шаблони змін', duration: 'Тривалість (гг:хх)', }, + pauseTemplates: { + pauseTemplates: 'Шаблони пауз', + pauseReason: 'Причина паузи', + duration: 'Тривалість (хх)', + }, }, routing: { routing: 'Маршрутизація', diff --git a/src/app/router/_internals/NavigationPages.lookup.js b/src/app/router/_internals/NavigationPages.lookup.js index ea3381e56..d92f441cc 100644 --- a/src/app/router/_internals/NavigationPages.lookup.js +++ b/src/app/router/_internals/NavigationPages.lookup.js @@ -106,6 +106,11 @@ const nav = Object.freeze([ locale: `WebitelApplications.${WebitelApplications.ADMIN}.sections.${AdminSections.SHIFT_TEMPLATES}`, route: 'shift-templates', }, + { + value: AdminSections.PAUSE_TEMPLATES, + locale: `WebitelApplications.${WebitelApplications.ADMIN}.sections.${AdminSections.PAUSE_TEMPLATES}`, + route: 'pause-templates', + }, ], }, { diff --git a/src/app/router/_internals/RouteNames.enum.js b/src/app/router/_internals/RouteNames.enum.js index cd3e29f5f..33484e672 100644 --- a/src/app/router/_internals/RouteNames.enum.js +++ b/src/app/router/_internals/RouteNames.enum.js @@ -26,6 +26,7 @@ export default Object.freeze({ PAUSE_CAUSE: 'agent-pause-cause', MEDIA: 'media', SHIFT_TEMPLATES: 'shift-templates', + PAUSE_TEMPLATES: 'pause-templates', // CONTACT-CENTER AGENTS: 'agents', diff --git a/src/app/router/router.js b/src/app/router/router.js index bfded31af..a8030d07c 100755 --- a/src/app/router/router.js +++ b/src/app/router/router.js @@ -29,11 +29,13 @@ import AgentSkillsRoutes from "../../modules/lookups/modules/agent-skills/router import BucketsRoutes from "../../modules/lookups/modules/buckets/router/buckets.js"; import BlacklistsRoutes from "../../modules/lookups/modules/blacklists/router/blacklists.js"; import MediaRoutes from "../../modules/lookups/modules/media/router/media.js"; -import ShiftTemplatesRoutes from "../../modules/lookups/modules/shift-templates/router/shiftTemplates.js"; +import ShiftTemplatesRoutes + from '../../modules/lookups/modules/shift-templates/router/shiftTemplates.js'; import CalendarsRoutes from "../../modules/lookups/modules/calendars/router/calendars.js"; import CommunicationsRoutes from "../../modules/lookups/modules/communications/router/communications.js"; import RegionsRoutes from "../../modules/lookups/modules/regions/router/regions.js"; import AgentPauseCauseRoutes from "../../modules/lookups/modules/agent-pause-cause/router/agentPauseCause.js"; +import PauseTemplatesRoutes from "../../modules/lookups/modules/pause-templates/router/pauseTemplates.js"; const ApplicationHub = () => import('../../modules/application-hub/components/application-hub.vue'); const ModuleWrap = () => import('../../modules/_shared/object-wrap/the-object-wrap.vue'); @@ -109,6 +111,7 @@ const router = createRouter({ ...RegionsRoutes, ...AgentPauseCauseRoutes, ...ShiftTemplatesRoutes, + ...PauseTemplatesRoutes, // ----------LOOKUPS END------------ // --------------CONTACT CENTER------------- diff --git a/src/modules/lookups/modules/agent-pause-cause/api/agentPauseCause.js b/src/modules/lookups/modules/agent-pause-cause/api/agentPauseCause.js index 201f61fe5..2860d3764 100644 --- a/src/modules/lookups/modules/agent-pause-cause/api/agentPauseCause.js +++ b/src/modules/lookups/modules/agent-pause-cause/api/agentPauseCause.js @@ -115,6 +115,12 @@ const deletePauseCause = async ({ id }) => { } }; +const getPauseCauseLookup = (params) => + getPauseCauseList({ + ...params, + fields: params.fields || ['id', 'name'], + }); + const AgentPauseCauseAPI = { getList: getPauseCauseList, get: getPauseCause, @@ -122,6 +128,7 @@ const AgentPauseCauseAPI = { patch: patchPauseCause, update: updatePauseCause, delete: deletePauseCause, + getLookup: getPauseCauseLookup, }; export default AgentPauseCauseAPI; diff --git a/src/modules/lookups/modules/pause-templates/api/pauseTemplates.js b/src/modules/lookups/modules/pause-templates/api/pauseTemplates.js new file mode 100644 index 000000000..41fc07185 --- /dev/null +++ b/src/modules/lookups/modules/pause-templates/api/pauseTemplates.js @@ -0,0 +1,121 @@ +import { getDefaultGetListResponse, getDefaultGetParams } from '@webitel/ui-sdk/src/api/defaults/index.js'; +import applyTransform, { + camelToSnake, + merge, + notify, + sanitize, + snakeToCamel, +} from '@webitel/ui-sdk/src/api/transformers/index.js'; +import deepCopy from 'deep-copy'; +import { PauseTemplateServiceApiFactory } from 'webitel-sdk'; + +import instance from '../../../../../app/api/instance'; +import configuration from '../../../../../app/api/openAPIConfig'; + +const pauseTemplateService = new PauseTemplateServiceApiFactory(configuration, '', instance); + +const getPauseTemplateList = async (params) => { + const { search: q, page, size, sort, fields } = applyTransform(params, [ + merge(getDefaultGetParams()), + ]); + + try { + const response = await pauseTemplateService.searchPauseTemplate(q, page, size, sort, fields); + const { items, next } = applyTransform(response.data, [ + snakeToCamel(), + merge(getDefaultGetListResponse()), + ]); + return { + items, + next, + }; + } catch (err) { + throw applyTransform(err, [notify]); + } +}; + +const itemResponseHandler = (item) => { + const obj = {...item.item}; + + obj.causes = obj.causes.map((cause) => { + return { + id: cause.cause?.id, + name: cause.cause?.name, + duration: cause.duration, + }; + }, []); + return obj; +} + +const preRequestHandler = (item) => { + const copy = deepCopy(item); + copy.causes = copy.causes.map((cause) => { + if(!cause.name && !cause.id) return cause; + return { + cause: { + id: cause?.id, + name: cause?.name, + }, + duration: cause.duration, + }; + }) + return copy; +}; + +const getPauseTemplate = async ({ itemId: id }) => { + + try { + const response = await pauseTemplateService.readPauseTemplate(id); + return applyTransform(response.data, [snakeToCamel(), itemResponseHandler]); + } catch (err) { + throw applyTransform(err, [notify]); + } +}; + +const fieldsToSend = ['name', 'description', 'causes', 'domainId', 'createdAt', 'createdBy', 'updatedAt', 'updatedBy']; + +const addPauseTemplate = async ({ itemInstance }) => { + const item = applyTransform(itemInstance, [sanitize(fieldsToSend), camelToSnake(), preRequestHandler]); + try { + const response = await pauseTemplateService.createPauseTemplate({ item: { ...item } }); + return applyTransform(response.data, [snakeToCamel(), itemResponseHandler]); + } catch (err) { + throw applyTransform(err, [notify]); + } +}; + +const updatePauseTemplate = async ({ itemInstance, itemId: id }) => { + const item = applyTransform(itemInstance, [sanitize(fieldsToSend), camelToSnake(), preRequestHandler]); + try { + const response = await pauseTemplateService.updatePauseTemplate(id, { item: { ...item }}); + return applyTransform(response.data, [snakeToCamel(), itemResponseHandler]); + } catch (err) { + throw applyTransform(err, [notify]); + } +}; + +const deleteShiftTemplate = async ({ id }) => { + try { + const response = await pauseTemplateService.deletePauseTemplate(id); + return applyTransform(response.data, []); + } catch (err) { + throw applyTransform(err, [notify]); + } +}; + +const getPauseTemplatesLookup = (params) => + getPauseTemplateList({ + ...params, + fields: params.fields || ['id', 'name'], + }); + +const PauseTemplatesAPI = { + getList: getPauseTemplateList, + get: getPauseTemplate, + add: addPauseTemplate, + update: updatePauseTemplate, + delete: deleteShiftTemplate, + getLookup: getPauseTemplatesLookup, +} + +export default PauseTemplatesAPI; diff --git a/src/modules/lookups/modules/pause-templates/components/opened-pause-template-causes.vue b/src/modules/lookups/modules/pause-templates/components/opened-pause-template-causes.vue new file mode 100644 index 000000000..73819f7d4 --- /dev/null +++ b/src/modules/lookups/modules/pause-templates/components/opened-pause-template-causes.vue @@ -0,0 +1,99 @@ + + + + + diff --git a/src/modules/lookups/modules/pause-templates/components/opened-pause-template-general.vue b/src/modules/lookups/modules/pause-templates/components/opened-pause-template-general.vue new file mode 100644 index 000000000..ca64dc858 --- /dev/null +++ b/src/modules/lookups/modules/pause-templates/components/opened-pause-template-general.vue @@ -0,0 +1,36 @@ + + + + + diff --git a/src/modules/lookups/modules/pause-templates/components/opened-pause-template.vue b/src/modules/lookups/modules/pause-templates/components/opened-pause-template.vue new file mode 100644 index 000000000..29e906865 --- /dev/null +++ b/src/modules/lookups/modules/pause-templates/components/opened-pause-template.vue @@ -0,0 +1,113 @@ + + + + + diff --git a/src/modules/lookups/modules/pause-templates/components/the-pause-templates.vue b/src/modules/lookups/modules/pause-templates/components/the-pause-templates.vue new file mode 100644 index 000000000..202e13ab8 --- /dev/null +++ b/src/modules/lookups/modules/pause-templates/components/the-pause-templates.vue @@ -0,0 +1,174 @@ + + + diff --git a/src/modules/lookups/modules/pause-templates/router/_internals/PauseTemplatesRouteNames.enum.js b/src/modules/lookups/modules/pause-templates/router/_internals/PauseTemplatesRouteNames.enum.js new file mode 100644 index 000000000..6d8269e9c --- /dev/null +++ b/src/modules/lookups/modules/pause-templates/router/_internals/PauseTemplatesRouteNames.enum.js @@ -0,0 +1,6 @@ +import RouteNames from '../../../../../../app/router/_internals/RouteNames.enum.js'; + +export default Object.freeze({ + GENERAL: `${RouteNames.PAUSE_TEMPLATES}-general`, + CAUSES: `${RouteNames.PAUSE_TEMPLATES}-causes`, +}); diff --git a/src/modules/lookups/modules/pause-templates/router/pauseTemplates.js b/src/modules/lookups/modules/pause-templates/router/pauseTemplates.js new file mode 100644 index 000000000..2995be4ec --- /dev/null +++ b/src/modules/lookups/modules/pause-templates/router/pauseTemplates.js @@ -0,0 +1,42 @@ +import RouteNames from "../../../../../app/router/_internals/RouteNames.enum.js"; +import { checkRouteAccess } from "../../../../../app/router/_internals/guards.js"; +import PauseTemplatesRouteNames + from './_internals/PauseTemplatesRouteNames.enum.js'; + +const PauseTemplates = () => import('../components/the-pause-templates.vue'); +const OpenedPauseTemplate = () => import('../components/opened-pause-template.vue'); + +const OpenedPauseTemplateGeneral = () => import('../components/opened-pause-template-general.vue'); +const OpenedPauseTemplateCauses = () => import('../components/opened-pause-template-causes.vue'); + + +const PauseTemplatesRoutes = [ + { + path: '/lookups/pause-templates', + name: RouteNames.PAUSE_TEMPLATES, + component: PauseTemplates, + beforeEnter: checkRouteAccess, + }, + { + path: '/lookups/pause-templates/:id', + name: `${RouteNames.PAUSE_TEMPLATES}-card`, + redirect: { + name: PauseTemplatesRouteNames.GENERAL + }, + component: OpenedPauseTemplate, + beforeEnter: checkRouteAccess, + children: [ + { + path: 'general', + name: PauseTemplatesRouteNames.GENERAL, + component: OpenedPauseTemplateGeneral, + }, + { + path: 'template', + name: PauseTemplatesRouteNames.CAUSES, + component: OpenedPauseTemplateCauses, + } + ], + }, +]; +export default PauseTemplatesRoutes; diff --git a/src/modules/lookups/modules/pause-templates/store/_internals/headers.js b/src/modules/lookups/modules/pause-templates/store/_internals/headers.js new file mode 100644 index 000000000..ff2ea4fd7 --- /dev/null +++ b/src/modules/lookups/modules/pause-templates/store/_internals/headers.js @@ -0,0 +1,16 @@ +import { SortSymbols } from '@webitel/ui-sdk/src/scripts/sortQueryAdapters'; + +export default [ + { + value: 'name', + locale: 'objects.name', + field: 'name', + sort: SortSymbols.NONE, + }, + { + value: 'description', + locale: 'objects.description', + field: 'description', + sort: SortSymbols.NONE, + }, +]; diff --git a/src/modules/lookups/modules/pause-templates/store/pause-templates.js b/src/modules/lookups/modules/pause-templates/store/pause-templates.js new file mode 100644 index 000000000..3c8af6f04 --- /dev/null +++ b/src/modules/lookups/modules/pause-templates/store/pause-templates.js @@ -0,0 +1,42 @@ +import ObjectStoreModule from '../../../../../app/store/BaseStoreModules/StoreModules/ObjectStoreModule'; +import PauseTemplatesAPI from '../api/pauseTemplates.js'; +import headers from './_internals/headers'; + +const resettableState = { + itemInstance: { + name: '', + description: '', + causes: [], + }, +}; + +const actions = { + ADD_CAUSE: (context) => { + const array = [...context.state.itemInstance.causes]; + array.push({ duration: 0 }); + context.dispatch('SET_ITEM_PROPERTY', { prop: 'causes', value: array }); + }, + SET_CAUSE: (context, { prop, index, value }) => { + const array = [...context.state.itemInstance.causes]; + + if(prop) { + array[index] = { ...array[index], duration: value }; + } else { + array[index] = { ...array[index], name: value.name, id: value.id }; + } + + context.dispatch('SET_ITEM_PROPERTY', { prop: 'causes', value: array }); + }, + REMOVE_CAUSE: (context, index) => { + const array = [...context.state.itemInstance.causes]; + array.splice(index, 1); + context.dispatch('SET_ITEM_PROPERTY', { prop: 'causes', value: array }); + }, +} + +const pauseTemplates = new ObjectStoreModule({ resettableState, headers }) +.attachAPIModule(PauseTemplatesAPI) +.generateAPIActions() +.getModule({actions}); + +export default pauseTemplates; diff --git a/src/modules/lookups/store/lookups.js b/src/modules/lookups/store/lookups.js index 1edd5820b..6985235ae 100644 --- a/src/modules/lookups/store/lookups.js +++ b/src/modules/lookups/store/lookups.js @@ -8,6 +8,7 @@ import media from '../modules/media/store/media'; import regions from '../modules/regions/store/regions'; import shiftTemplates from '../modules/shift-templates/store/shift-templates.js'; +import pauseTemplates from '../modules/pause-templates/store/pause-templates.js'; const modules = { skills, @@ -19,6 +20,7 @@ const modules = { pauseCause, media, shiftTemplates, + pauseTemplates, }; export default {