Skip to content

Commit

Permalink
feature: fixes in team scheme module [WTEL-4354]
Browse files Browse the repository at this point in the history
  • Loading branch information
lizacoma committed Apr 15, 2024
1 parent d2b0dbd commit e597c1b
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 97 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"vue-router": "^4.2.5",
"vue2-dropzone": "^3.6.0",
"vuex": "^4.1.0",
"webitel-sdk": "^24.2.3"
"webitel-sdk": "^24.02.06"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.4.0",
Expand Down
5 changes: 5 additions & 0 deletions src/app/locale/en/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,11 @@ export default {
agentStatus: 'Agent status changed',
}
},
scheme: {
scheme: 'Scheme | Schemes',
addScheme: 'Add scheme',
editScheme: 'Edit scheme',
},
},

members: {
Expand Down
5 changes: 5 additions & 0 deletions src/app/locale/ru/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,11 @@ export default {
agentStatus: 'Изменение статуса оператора',
}
},
scheme: {
scheme: 'Схема | Схемы',
addScheme: 'Добавить схему',
editScheme: 'Редактировать схему',
},
},

members: {
Expand Down
5 changes: 5 additions & 0 deletions src/app/locale/ua/ua.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,11 @@ export default {
agentStatus: 'Зміна статуту оператора',
}
},
scheme: {
scheme: 'Схема | Схеми',
addScheme: 'Додати схему',
editScheme: 'Редагувати схему',
},
},

members: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default {
text: this.$tc('objects.ccenter.queues.hooks.hooks', 2),
value: 'hooks',
}, {
text: 'schemes',
text: this.$tc('objects.ccenter.teams.scheme.scheme', 2),
value: 'schemes',
}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import FlowsAPI from '../../../../../../routing/modules/flow/api/flow';
import HookEvent from '../enum/HookTeamEvent.enum';
export default {
name: 'OpenedQueueHooksPopup',
name: 'OpenedTeamHooksPopup',
mixins: [nestedObjectMixin],
setup: () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
import { AgentServiceApiFactory } from 'webitel-sdk';
import { TeamTriggerServiceApi } from 'webitel-sdk';
import {
getDefaultGetListResponse,
getDefaultGetParams,
} from '@webitel/ui-sdk/src/api/defaults';
import applyTransform, {
camelToSnake,
merge, mergeEach,
notify,
notify, sanitize,
snakeToCamel,
starToSearch,
} from '@webitel/ui-sdk/src/api/transformers';
import instance from '../../../../../../../app/api/instance';
import configuration from '../../../../../../../app/api/openAPIConfig';

const agentService = new AgentServiceApiFactory(configuration, '', instance);
const schemeService = new TeamTriggerServiceApi(configuration, '', instance);

const getTeamSchemesList = async (params) => {
const fields = ['id', 'name', 'status', 'supervisor', 'skills'];
const fieldsToSend = ['name', 'schema', 'enabled', 'description'];

const preRequestHandler = (parentId) => (item) => ({
...item,
teamId: parentId,
});

const getTeamSchemesList = async (params) => {
const defaultObject = {
name: '',
status: '',
supervisor: {},
skills: [],
enabled: false,
};

const {
parentId,
page = 1,
size = 10,
page,
size,
search,
sort,
fields,
id,
enabled,
parentId,
} = applyTransform(params, [
merge(getDefaultGetParams()),
starToSearch('search'),
]);

try {
const response = await agentService.searchAgent(
const response = await schemeService.searchTeamTrigger(
parentId,
page,
size,
search,
sort,
fields,
undefined,
undefined,
undefined,
parentId,
enabled,
id,
);
const { items, next } = applyTransform(response.data, [
snakeToCamel(),
Expand All @@ -65,14 +69,20 @@ const getTeamSchemesList = async (params) => {
}
};

const getTeamSchemes = async ({ itemId: id }) => {
const responseHandler = (agent) => ({ agent });
const getTeamSchemes = async ({ parentId, itemId: id }) => {

const defaultObject = {
name: '',
description: '',
enabled: false,
schema: {},
};

try {
const response = await agentService.readAgent(id);
const response = await schemeService.readTeamTrigger(parentId, id);
return applyTransform(response.data, [
snakeToCamel(),
responseHandler,
merge(defaultObject),
]);
} catch (err) {
throw applyTransform(err, [
Expand All @@ -81,27 +91,50 @@ const getTeamSchemes = async ({ itemId: id }) => {
}
};

const addTeamSchemes = ({ parentId, itemInstance }) => {
const { id } = itemInstance.agent;
const changes = { team: { id: parentId } };
return patchAgent({ id, changes });
const addTeamSchemes = async ({ parentId, itemInstance }) => {
const item = applyTransform(itemInstance, [
preRequestHandler(parentId),
sanitize(fieldsToSend),
camelToSnake(),
]);
try {
const response = await schemeService.createTeamTrigger(parentId, item);
return applyTransform(response.data, [
snakeToCamel(),
]);
} catch (err) {
throw applyTransform(err, [
notify,
]);
}
};

const updateTeamSchemes = async ({ parentId, itemId, itemInstance }) => {
const patchTeamSchemes = async ({ changes, id, parentId }) => {
const body = applyTransform(changes, [
sanitize(fieldsToSend),
camelToSnake(),
]);

try {
await addTeamAgent({ parentId, itemInstance });
await deleteTeamAgent({ id: itemId });
const response = await schemeService.patchTeamTrigger(parentId, id, body);
return applyTransform(response.data, [
snakeToCamel(),
]);
} catch (err) {
throw err;
throw applyTransform(err, [
notify,
]);
}
};

const patchSchemes = async ({ id, changes }) => {
const item = applyTransform(changes, [
const updateTeamSchemes = async ({ itemInstance, itemId: id, parentId }) => {
const item = applyTransform(itemInstance, [
preRequestHandler(parentId),
sanitize(fieldsToSend),
camelToSnake(),
]);
try {
const response = await agentService.patchAgent(id, item);
const response = await schemeService.updateTeamTrigger(parentId, id, item);
return applyTransform(response.data, [
snakeToCamel(),
]);
Expand All @@ -112,17 +145,23 @@ const patchSchemes = async ({ id, changes }) => {
}
};

const deleteTeamSchemes = ({ id }) => {
const changes = { team: { id: null } };
return patchAgent({ id, changes });
const deleteTeamSchemes = async ({ parentId, id }) => {
try {
const response = await schemeService.deleteTeamTrigger(parentId, id);
return applyTransform(response.data, []);
} catch (err) {
throw applyTransform(err, [
notify,
]);
}
};

const TeamAgentsAPI = {
getList: getTeamSchemesList,
get: getTeamSchemes,
add: addTeamSchemes,
update: updateTeamSchemes,
putch: patchSchemes,
patch: patchTeamSchemes,
delete: deleteTeamSchemes,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@
@close="close"
>
<template #title>
{{ $tc('objects.ccenter.agents.agents', 1) }}
{{ itemInstance.id
? $tc('objects.ccenter.teams.scheme.editScheme')
: $tc('objects.ccenter.teams.scheme.addScheme') }}
</template>
<template #main>
<form>
<wt-input
:label="$t('objects.name')"
:v="v$.itemInstance.name"
:value="itemInstance.name"
required
@input="setItemProp({ prop: 'name', value: $event })"
/>
<wt-select
:clearable="false"
:label="$tc('objects.ccenter.agents.agents', 1)"
:search-method="loadAgentsOptions"
:v="v$.itemInstance.agent"
:value="itemInstance.agent"
:label="$tc('objects.routing.flow.flow', 1)"
:search-method="loadFlowOptions"
:v="v$.itemInstance.schema"
:value="itemInstance.schema"
required
@input="setItemProp({ prop: 'agent', value: $event })"
@input="setItemProp({ prop: 'schema', value: $event })"
/>
</form>
</template>
Expand All @@ -25,7 +34,7 @@
:disabled="disabledSave"
@click="save"
>
{{ $t('objects.add') }}
{{ $t('objects.save') }}
</wt-button>
<wt-button
color="secondary"
Expand All @@ -38,35 +47,37 @@
</template>

<script>
import { EngineRoutingSchemaType } from 'webitel-sdk';
import { useVuelidate } from '@vuelidate/core';
import { required } from '@vuelidate/validators';
import nestedObjectMixin from '../../../../../../../app/mixins/objectPagesMixins/openedObjectMixin/nestedObjectMixin';
import AgentsAPI from '../../../../agents/api/agents';
import FlowsAPI from '../../../../../../routing/modules/flow/api/flow';
export default {
name: 'OpenedTeamAgentPopup',
name: 'OpenedTeamSchemePopup',
mixins: [nestedObjectMixin],
setup: () => ({
v$: useVuelidate(),
}),
data: () => ({
namespace: 'ccenter/teams/agents',
namespace: 'ccenter/teams/schemes',
}),
validations: {
itemInstance: {
agent: { required },
name: { required },
schema: { required },
},
},
methods: {
loadAgentsOptions(params) {
return AgentsAPI.getLookup(params);
loadFlowOptions(params) {
return FlowsAPI.getLookup({ ...params, type: [EngineRoutingSchemaType.Service] });
},
},
};
</script>

<style lang="scss" scoped>
</style>
Loading

0 comments on commit e597c1b

Please sign in to comment.