Skip to content

Commit

Permalink
Merge pull request #170 from webitel/feature/sources-page
Browse files Browse the repository at this point in the history
feature/add-sources-page
  • Loading branch information
Lera24 authored Dec 6, 2024
2 parents dae9218 + 2e3ae84 commit be8715b
Show file tree
Hide file tree
Showing 14 changed files with 709 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/app/locale/en/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import AccessMode
from '../../../modules/contacts/modules/permissions/enums/AccessMode.enum.js';
import TimelineTaskStatusEnum
from '../../../modules/contacts/modules/timeline/enums/TimelineTaskStatus.enum.js';
import TypesSourcesEnum
from '../../../modules/configuration/modules/lookups/modules/sources/enums/TypesSources.enum.js';

export default {
crm: 'CRM',
Expand Down Expand Up @@ -109,8 +111,19 @@ export default {
validFrom: 'Valid from',
validTo: 'Valid to',
},
sources: {
sources: 'Case source | Case sources',
types: {
[TypesSourcesEnum.CALL]: 'Call',
[TypesSourcesEnum.CHAT]: 'Chat',
[TypesSourcesEnum.SOCIAL_MEDIA]: 'Social Media',
[TypesSourcesEnum.EMAIL]: 'Email',
[TypesSourcesEnum.API]: 'API',
[TypesSourcesEnum.MANUAL]: 'Manual',
}
},

[CrmSections.CONTACT_GROUPS]: 'Contact groups',
[CrmSections.STATUSES]: 'Statuses',
[CrmSections.SOURCES]: 'Sources',
},
};
15 changes: 14 additions & 1 deletion src/app/locale/ru/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { WebitelContactsTimelineEventType } from 'webitel-sdk';
import ChatGatewayProvider
from '@webitel/ui-sdk/src/enums/ChatGatewayProvider/ChatGatewayProvider.enum.js';
import CrmSections from '@webitel/ui-sdk/src/enums/WebitelApplications/CrmSections.enum';
import TypesSourcesEnum
from '../../../modules/configuration/modules/lookups/modules/sources/enums/TypesSources.enum.js';
import AccessMode
from '../../../modules/contacts/modules/permissions/enums/AccessMode.enum.js';
import TimelineTaskStatusEnum
Expand Down Expand Up @@ -108,8 +110,19 @@ export default {
validFrom: 'Действителен с',
validTo: 'Действителен до',
},

sources: {
sources: 'Источник обращений | Источники обращений',
types: {
[TypesSourcesEnum.CALL]: 'Звонок',
[TypesSourcesEnum.CHAT]: 'Чат',
[TypesSourcesEnum.SOCIAL_MEDIA]: 'Социальная сеть',
[TypesSourcesEnum.EMAIL]: 'Письмо',
[TypesSourcesEnum.API]: 'API',
[TypesSourcesEnum.MANUAL]: 'Созданное вручную',
},
},
[CrmSections.CONTACT_GROUPS]: 'Группы контактов',
[CrmSections.STATUSES]: 'Статусы',
[CrmSections.SOURCES]: 'Источники',
},
};
15 changes: 14 additions & 1 deletion src/app/locale/ua/ua.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { WebitelContactsTimelineEventType } from 'webitel-sdk';
import ChatGatewayProvider
from '@webitel/ui-sdk/src/enums/ChatGatewayProvider/ChatGatewayProvider.enum.js';
import CrmSections from '@webitel/ui-sdk/src/enums/WebitelApplications/CrmSections.enum';
import TypesSourcesEnum
from '../../../modules/configuration/modules/lookups/modules/sources/enums/TypesSources.enum.js';
import AccessMode
from '../../../modules/contacts/modules/permissions/enums/AccessMode.enum.js';
import TimelineTaskStatusEnum
Expand Down Expand Up @@ -109,8 +111,19 @@ export default {
validTo: 'Дійсний до',
},

sources: {
sources: 'Джерело звернень | Джерела звернень',

types: {
[TypesSourcesEnum.CALL]: 'Дзвінок',
[TypesSourcesEnum.CHAT]: 'Чат',
[TypesSourcesEnum.SOCIAL_MEDIA]: 'Соціальна мережа',
[TypesSourcesEnum.EMAIL]: 'Лист',
[TypesSourcesEnum.API]: 'API',
[TypesSourcesEnum.MANUAL]: 'Створене вручну',
},
},
[CrmSections.CONTACT_GROUPS]: 'Групи контактів',
[CrmSections.STATUSES]: 'Статуси',
[CrmSections.SOURCES]: 'Джерела',
},
};
27 changes: 26 additions & 1 deletion src/app/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import TheSlas
from '../../modules/configuration/modules/lookups/modules/slas/components/the-slas.vue';
import OpenedSla from '../../modules/configuration/modules/lookups/modules/slas/components/opened-sla.vue';
import OpenedSlaGeneral from '../../modules/configuration/modules/lookups/modules/slas/components/opened-sla-general.vue';
import TheSources
from '../../modules/configuration/modules/lookups/modules/sources/components/the-sources.vue';
import OpenedSource
from '../../modules/configuration/modules/lookups/modules/sources/components/opened-source.vue';
import OpenedSourceGeneral
from '../../modules/configuration/modules/lookups/modules/sources/components/opened-source-general.vue';


import store from '../store';
Expand Down Expand Up @@ -148,7 +154,26 @@ const routes = [
// component: SlasConditions,
// },
],
}
},
{
path: 'sources',
name: CrmSections.SOURCES,
component: TheSources,
// beforeEnter: checkRouteAccess,
},
{
path: 'sources/:id',
name: `${CrmSections.SOURCES}-card`,
component: OpenedSource,
redirect: { name: `${CrmSections.SOURCES}-general` },
children: [
{
path: 'general',
name: `${CrmSections.SOURCES}-general`,
component: OpenedSourceGeneral,
},
],
},
],
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/modules/configuration/components/the-configuration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const nav = [
subNav: [
{
value: CrmSections.SOURCES,
name: t('lookups.sources'),
name: t('lookups.sources.sources', 2),
route: 'lookups/sources',
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import {
getDefaultGetListResponse,
getDefaultGetParams,
getDefaultInstance,
getDefaultOpenAPIConfig,
} from '@webitel/ui-sdk/src/api/defaults/index.js';
import applyTransform, {
camelToSnake,
merge,
notify,
sanitize,
snakeToCamel,
starToSearch,
} from '@webitel/ui-sdk/src/api/transformers/index.js';
import { SourcesApiFactory } from 'webitel-sdk';

const instance = getDefaultInstance();
const configuration = getDefaultOpenAPIConfig();

const sourceService = new SourcesApiFactory(configuration, '', instance);

const fieldsToSend = ['name', 'description', 'type'];

const getSourcesList = async (params) => {
const fieldsToSend = ['page', 'size', 'q', 'sort', 'fields', 'id'];

const listResponseHandler = (items) => {
return items.map((item) => ({
...item,
type: item.type.toLowerCase(),
}));
};

const {
page,
size,
fields,
sort,
id,
q,
type,
} = applyTransform(params, [
merge(getDefaultGetParams()),
starToSearch('search'),
(params) => ({ ...params, q: params.search }),
sanitize(fieldsToSend),
camelToSnake(),
]);

try {
const response = await sourceService.listSources(
page,
size,
fields,
sort,
id,
q,
type,
)
const { items, next } = applyTransform(response.data, [
merge(getDefaultGetListResponse()),
]);
return {
items: applyTransform(items, [listResponseHandler]),
next,
};
} catch (err) {
throw applyTransform(err, [notify]);
}
};

const getSource = async ({ itemId: id }) => {
const itemResponseHandler = (item) => {
if(item.source.type) {
item.source.type = item.source.type.toLowerCase();
}
return item.source;
};

try {
const response = await sourceService.locateSource(id);
return applyTransform(response.data, [
snakeToCamel(),
itemResponseHandler,
]);
} catch (err) {
throw applyTransform(err, [notify]);
}
};

const preRequestHandler = (item) => {
return {
...item,
type: item.type.toUpperCase(),
}
};

const addSource = async ({ itemInstance }) => {
const item = applyTransform(itemInstance, [
preRequestHandler,
sanitize(fieldsToSend),
camelToSnake(),
]);
try {
const response = await sourceService.createSource(item);
return applyTransform(response.data, [
snakeToCamel()
]);
} catch (err) {
throw applyTransform(err, [notify]);
}
};

const updateSource = async ({ itemInstance, itemId: id }) => {
const item = applyTransform(itemInstance, [
preRequestHandler,
camelToSnake(),
sanitize(fieldsToSend)]);

try {
const response = await sourceService.updateSource(id, item);
return applyTransform(response.data, [snakeToCamel()]);
} catch (err) {
throw applyTransform(err, [notify]);
}
};

const deleteSource = async ({ id }) => {
try {
const response = await sourceService.deleteSource(id);
return applyTransform(response.data, []);
} catch (err) {
throw applyTransform(err, [notify]);
}
};

const SourcesAPI = {
getList: getSourcesList,
get: getSource,
add: addSource,
update: updateSource,
delete: deleteSource,
}

export default SourcesAPI;
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<template>
<section>
<header class="opened-card-header">
<h3 class="opened-card-header__title">
{{ t('reusable.generalInfo') }}
</h3>
</header>
<div class="opened-card-input-grid">
<wt-input
:label="t('reusable.name')"
:value="itemInstance.name"
required
@input="setItemProp({ path: 'name', value: $event })"
/>

<wt-select
:label="t('vocabulary.type')"
:options="typesSourcesOptions"
:value="currentTypeSource"
required
@input="setItemProp({ path: 'type', value: $event.id })"
/>

<wt-textarea
:label="t('vocabulary.description')"
:value="itemInstance.description"
@input="setItemProp({ path: 'description', value: $event })"
/>
</div>
</section>
</template>

<script setup>
import { computed } from 'vue';
import { useCardStore } from '@webitel/ui-sdk/store';
import { useI18n } from 'vue-i18n';
import TypesSources from '../enums/TypesSources.enum.js';
const props = defineProps({
namespace: {
type: String,
required: true,
},
});
const { t } = useI18n();
const { itemInstance, setItemProp } = useCardStore(props.namespace);
const typesSourcesOptions = computed(() => Object.values(TypesSources).map((type) => {
return {
id: type,
name: t(`lookups.sources.types.${type}`),
};
}));
const currentTypeSource = computed(() => {
return typesSourcesOptions.value.find((type) => type.id === itemInstance.value?.type);
});
</script>
<style lang="scss" scoped>
</style>
Loading

0 comments on commit be8715b

Please sign in to comment.