-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #783 from webitel/feature/add-pause-template-page
feature: add pause template page[WTEL-5080]
- Loading branch information
Showing
17 changed files
with
683 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/modules/lookups/modules/pause-templates/api/pauseTemplates.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
99 changes: 99 additions & 0 deletions
99
src/modules/lookups/modules/pause-templates/components/opened-pause-template-causes.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<template> | ||
<section class="opened-pause-template-causes"> | ||
<header class="content-header"> | ||
<h3 class="content-title"> | ||
{{ $tc('objects.routing.chatGateways.templates.templates', 1) }} | ||
</h3> | ||
|
||
<div class="content-header__actions-wrap"> | ||
<wt-icon-btn | ||
v-if="!disableUserInput" | ||
class="icon-action" | ||
icon="plus" | ||
@click="addCause" | ||
/> | ||
</div> | ||
</header> | ||
|
||
<div class="table-wrapper"> | ||
<div class="table-wrapper__visible-scroll-wrapper"> | ||
<wt-table | ||
:data="itemInstance.causes" | ||
:grid-actions="!disableUserInput" | ||
:headers="headers" | ||
:selectable="false" | ||
> | ||
<template #name="{ item, index }"> | ||
<wt-select | ||
:search-method="loadAgentPauseCause" | ||
:value="item.name" | ||
@input="setCause({ index, value: $event })" | ||
/> | ||
</template> | ||
<template #duration="{ item, index }"> | ||
<wt-input | ||
class="opened-pause-template-causes__duration" | ||
:disabled="disableUserInput" | ||
:value="item.duration" | ||
type="number" | ||
required | ||
@input="setCause({ prop: 'duration', index, value: $event })" | ||
/> | ||
</template> | ||
<template #actions="{ item, index }"> | ||
<wt-icon-action | ||
action="delete" | ||
@click="removeCause(index)" | ||
/> | ||
</template> | ||
</wt-table> | ||
</div> | ||
</div> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
import { mapActions } from 'vuex'; | ||
import openedTabComponentMixin from '../../../../../app/mixins/objectPagesMixins/openedObjectTabMixin/openedTabComponentMixin'; | ||
import AgentPauseCauseAPI from '../../agent-pause-cause/api/agentPauseCause.js'; | ||
export default { | ||
name: 'OpenedPauseTemplateCauses', | ||
mixins: [openedTabComponentMixin], | ||
computed: { | ||
headers() { | ||
return [ | ||
{ | ||
value: 'name', | ||
text: this.$t('objects.lookups.pauseTemplates.pauseReason'), | ||
}, | ||
{ | ||
value: 'duration', | ||
text: this.$t('objects.lookups.pauseTemplates.duration'), | ||
}, | ||
]; | ||
}, | ||
}, | ||
methods: { | ||
...mapActions({ | ||
addCause(dispatch, payload) { | ||
dispatch(`${this.namespace}/ADD_CAUSE`, payload); | ||
}, | ||
setCause(dispatch, payload) { | ||
dispatch(`${this.namespace}/SET_CAUSE`, payload); | ||
}, | ||
removeCause(dispatch, payload) { | ||
dispatch(`${this.namespace}/REMOVE_CAUSE`, payload); | ||
}, | ||
}), | ||
loadAgentPauseCause(params) { | ||
return AgentPauseCauseAPI.getLookup(params); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.opened-pause-template-causes__duration { | ||
width: 100%; | ||
} | ||
</style> |
36 changes: 36 additions & 0 deletions
36
src/modules/lookups/modules/pause-templates/components/opened-pause-template-general.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<template> | ||
<section> | ||
<header class="content-header"> | ||
<h3 class="content-title"> | ||
{{ $t('objects.generalInfo') }} | ||
</h3> | ||
</header> | ||
<div class="object-input-grid object-input-grid__1-col object-input-grid__w50"> | ||
<wt-input | ||
:disabled="disableUserInput" | ||
:label="$t('objects.name')" | ||
:value="itemInstance.name" | ||
:v="v.itemInstance.name" | ||
required | ||
@input="setItemProp({ prop: 'name', value: $event })" | ||
/> | ||
<wt-textarea | ||
:disabled="disableUserInput" | ||
:label="$t('objects.description')" | ||
:value="itemInstance.description" | ||
@input="setItemProp({ prop: 'description', value: $event })" | ||
/> | ||
</div> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
import openedTabComponentMixin from '../../../../../app/mixins/objectPagesMixins/openedObjectTabMixin/openedTabComponentMixin'; | ||
export default { | ||
name: 'OpenedPauseTemplateGeneral', | ||
mixins: [openedTabComponentMixin], | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
</style> |
Oops, something went wrong.