From 340dcbb0b3f47bd98b5c9b9d736bfc12bcf1e60f Mon Sep 17 00:00:00 2001 From: Sviatoslav Bar Date: Sun, 15 Sep 2024 21:36:45 +0300 Subject: [PATCH] Feat/ contact-groups - api, router store [WTEL-4740] --- .../modules/cgroups/api/contact-groups.js | 141 ++++++++++++++++++ .../cgroups/assets/adm-agent-history-dark.svg | 15 ++ .../assets/adm-agent-history-light.svg | 15 ++ .../ContactGroupsRouteNames.enum.js | 6 + .../modules/cgroups/router/contact-groups.js | 39 +++++ .../cgroups/store/_internals/headers.js | 16 ++ .../modules/cgroups/store/contact-groups.js | 46 ++++++ .../modules/contact-groups/store/cgroups.js | 10 ++ 8 files changed, 288 insertions(+) create mode 100644 src/modules/lookups/modules/contact-groups/modules/cgroups/api/contact-groups.js create mode 100644 src/modules/lookups/modules/contact-groups/modules/cgroups/assets/adm-agent-history-dark.svg create mode 100644 src/modules/lookups/modules/contact-groups/modules/cgroups/assets/adm-agent-history-light.svg create mode 100644 src/modules/lookups/modules/contact-groups/modules/cgroups/router/_internals/ContactGroupsRouteNames.enum.js create mode 100644 src/modules/lookups/modules/contact-groups/modules/cgroups/router/contact-groups.js create mode 100644 src/modules/lookups/modules/contact-groups/modules/cgroups/store/_internals/headers.js create mode 100644 src/modules/lookups/modules/contact-groups/modules/cgroups/store/contact-groups.js create mode 100644 src/modules/lookups/modules/contact-groups/store/cgroups.js diff --git a/src/modules/lookups/modules/contact-groups/modules/cgroups/api/contact-groups.js b/src/modules/lookups/modules/contact-groups/modules/cgroups/api/contact-groups.js new file mode 100644 index 00000000..92c1058b --- /dev/null +++ b/src/modules/lookups/modules/contact-groups/modules/cgroups/api/contact-groups.js @@ -0,0 +1,141 @@ +import { + getDefaultGetListResponse, + getDefaultGetParams, +} from '@webitel/ui-sdk/src/api/defaults/index.js'; +import applyTransform, { + camelToSnake, + merge, + mergeEach, + log, + notify, + sanitize, + snakeToCamel, + starToSearch, + generateUrl, +} from '@webitel/ui-sdk/src/api/transformers/index.js'; + +import instance from '../../../../../../../app/api/instance'; + +const contactGroupsUrl = '/contacts/groups'; + +const getContactGroupsList = async (params) => { + const fieldsToSend = ['page', 'size', 'fields', 'sort', 'id', 'q', 'name']; + + const defaultObject = { + }; + + const url = applyTransform(params, [ + starToSearch('search'), + (params) => ({ ...params, q: params.search }), + sanitize(fieldsToSend), + camelToSnake(), + generateUrl(contactGroupsUrl), + ]); + + try { + const response = await instance.get(url); + + const { items, next } = applyTransform(response.data, [ + snakeToCamel(), + merge(getDefaultGetListResponse()), + ]); + return { + items: applyTransform(items, [mergeEach(defaultObject), log]), + next, + }; + + } catch (err) { + throw applyTransform(err, [notify]); + } +}; + +const getAgent = async ({ itemId: id }) => { + const url = `${contactGroupsUrl}/${id}`; + const defaultObject = { + }; + + try { + const response = await instance.get(url); + + return applyTransform(response.data.group, [ + snakeToCamel(), + merge(defaultObject), + ]); + } catch (err) { + throw applyTransform(err, [notify]); + } +}; + +const fieldsToSend = [ + 'name', + 'description', +]; + +const addAgent = async ({ itemInstance }) => { + const item = applyTransform(itemInstance, [ + sanitize(fieldsToSend), + camelToSnake(), + ]); + + try { + const response = await instance.post(contactGroupsUrl, item); + return applyTransform(response.data, []); + } catch (err) { + throw applyTransform(err, [notify]); + } +}; + +const patchAgent = async ({ itemInstance, id }) => { + const url = `${contactGroupsUrl}/${id}`; + + const item = applyTransform(itemInstance, [ + sanitize(fieldsToSend), + camelToSnake(), + ]); + + try { + const response = await instance.patch(url, item); + return applyTransform(response.data, []); + } catch (err) { + throw applyTransform(err, [notify]); + } +}; + +const updateAgent = async ({ itemInstance, itemId: id }) => { + const url = `${contactGroupsUrl}/${id}`; + + const item = applyTransform(itemInstance, [ + sanitize(fieldsToSend), + camelToSnake(), + ]); + + try { + const response = await instance.put(url, item); + return applyTransform(response.data, []); + } catch (err) { + throw applyTransform(err, [notify]); + } +}; + +const deleteAgent = async ({ id }) => { + const url = `${contactGroupsUrl}/${id}` + + try { + const response = await instance.delete(url); + return applyTransform(response.data, []); + } catch (err) { + throw applyTransform(err, [notify]); + } +}; + +const ContactGroupsAPI = { + getList: getContactGroupsList, + getListGroups: getContactGroupsList, + get: getAgent, + add: addAgent, + patch: patchAgent, + update: updateAgent, + delete: deleteAgent, +}; + +export default ContactGroupsAPI; diff --git a/src/modules/lookups/modules/contact-groups/modules/cgroups/assets/adm-agent-history-dark.svg b/src/modules/lookups/modules/contact-groups/modules/cgroups/assets/adm-agent-history-dark.svg new file mode 100644 index 00000000..8158c374 --- /dev/null +++ b/src/modules/lookups/modules/contact-groups/modules/cgroups/assets/adm-agent-history-dark.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/modules/lookups/modules/contact-groups/modules/cgroups/assets/adm-agent-history-light.svg b/src/modules/lookups/modules/contact-groups/modules/cgroups/assets/adm-agent-history-light.svg new file mode 100644 index 00000000..67b91b1f --- /dev/null +++ b/src/modules/lookups/modules/contact-groups/modules/cgroups/assets/adm-agent-history-light.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/modules/lookups/modules/contact-groups/modules/cgroups/router/_internals/ContactGroupsRouteNames.enum.js b/src/modules/lookups/modules/contact-groups/modules/cgroups/router/_internals/ContactGroupsRouteNames.enum.js new file mode 100644 index 00000000..226de5f8 --- /dev/null +++ b/src/modules/lookups/modules/contact-groups/modules/cgroups/router/_internals/ContactGroupsRouteNames.enum.js @@ -0,0 +1,6 @@ +import RouteNames from "../../../../../../../../app/router/_internals/RouteNames.enum.js"; + +export default Object.freeze({ + GENERAL: `${RouteNames.CONTACT_GROUPS}-general`, + PERMISSIONS: `${RouteNames.CONTACT_GROUPS}-permissions`, +}); diff --git a/src/modules/lookups/modules/contact-groups/modules/cgroups/router/contact-groups.js b/src/modules/lookups/modules/contact-groups/modules/cgroups/router/contact-groups.js new file mode 100644 index 00000000..90869368 --- /dev/null +++ b/src/modules/lookups/modules/contact-groups/modules/cgroups/router/contact-groups.js @@ -0,0 +1,39 @@ +import RouteNames from "../../../../../../../app/router/_internals/RouteNames.enum.js"; +import ContactGroupsRouteNames from "./_internals/ContactGroupsRouteNames.enum.js"; + +const ContactGroups = () => import( '../components/the-contact-groups.vue'); +const Agent = () => import('../components/opened-contact-groups.vue'); +const General = () => import("../components/opened-contact-groups-general.vue"); +const Permissions = () => import("../../../../../../_shared/permissions-tab/components/permissions-tab.vue"); + +import {checkRouteAccess} from "../../../../../../../app/router/_internals/guards.js"; + + +const ContactGroupsRoutes = [ + { + path: '/lookups/contact-groups', + name: RouteNames.CONTACT_GROUPS, + component: ContactGroups, + beforeEnter: checkRouteAccess, + }, + { + path: '/lookups/contact-groups/:id', + name: `${RouteNames.CONTACT_GROUPS}-card`, + redirect: { name: ContactGroupsRouteNames.GENERAL }, + component: Agent, + beforeEnter: checkRouteAccess, + children: [ + { + path: 'general', + name: ContactGroupsRouteNames.GENERAL, + component: General, + },{ + path: 'permissions/:permissionId?', + name: ContactGroupsRouteNames.PERMISSIONS, + component: Permissions, + } + ], + }, +] + +export default ContactGroupsRoutes; diff --git a/src/modules/lookups/modules/contact-groups/modules/cgroups/store/_internals/headers.js b/src/modules/lookups/modules/contact-groups/modules/cgroups/store/_internals/headers.js new file mode 100644 index 00000000..ff2ea4fd --- /dev/null +++ b/src/modules/lookups/modules/contact-groups/modules/cgroups/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/contact-groups/modules/cgroups/store/contact-groups.js b/src/modules/lookups/modules/contact-groups/modules/cgroups/store/contact-groups.js new file mode 100644 index 00000000..13c73f34 --- /dev/null +++ b/src/modules/lookups/modules/contact-groups/modules/cgroups/store/contact-groups.js @@ -0,0 +1,46 @@ +import HistoryStoreModule from '../../../../../../../app/store/BaseStoreModules/StoreModules/HistoryStoreModule/HistoryStoreModule'; +import ObjectStoreModule from '../../../../../../../app/store/BaseStoreModules/StoreModules/ObjectStoreModule'; +import PermissionsStoreModule from '../../../../../../../app/store/BaseStoreModules/StoreModules/PermissionsStoreModule/PermissionsStoreModule'; +import ContactGroupsAPI from '../api/contact-groups'; +import headers from './_internals/headers'; + +const resettableState = { + itemInstance: { + user: {}, + team: {}, + supervisor: [], + auditor: [], + region: {}, + progressiveCount: 1, + chatCount: 1, + taskCount: 1, + isSupervisor: false, + greetingMedia: {}, + }, +}; + +const actions = { + RESET_ITEM_STATE: async (context) => { + context.commit('RESET_ITEM_STATE'); + }, +}; + +const PERMISSIONS_API_URL = '/contacts/groups'; +const permissions = new PermissionsStoreModule() + .generateAPIActions(PERMISSIONS_API_URL) + .getModule(); + +const history = new HistoryStoreModule() + .generateGetListAction(ContactGroupsAPI.getAgentHistory) + .getModule(); + +const contactGroups = new ObjectStoreModule({ resettableState, headers }) + .attachAPIModule(ContactGroupsAPI) + .generateAPIActions() + .setChildModules({ + history, + permissions, + }) + .getModule({ actions }); + +export default contactGroups; diff --git a/src/modules/lookups/modules/contact-groups/store/cgroups.js b/src/modules/lookups/modules/contact-groups/store/cgroups.js new file mode 100644 index 00000000..995603d6 --- /dev/null +++ b/src/modules/lookups/modules/contact-groups/store/cgroups.js @@ -0,0 +1,10 @@ +import contactGroups from '../modules/cgroups/store/contact-groups'; + +const modules = { + groups: contactGroups, +}; + +export default { + namespaced: true, + modules, +};