-
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 #642 from webitel/feature/teams-hooks
Feature/teams hooks [WTEL-4246]
- Loading branch information
Showing
16 changed files
with
452 additions
and
7 deletions.
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
File renamed without changes.
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
167 changes: 167 additions & 0 deletions
167
src/modules/contact-center/modules/teams/modules/hooks/api/teamHooks.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,167 @@ | ||
import { | ||
getDefaultGetListResponse, | ||
getDefaultGetParams, | ||
} from '@webitel/ui-sdk/src/api/defaults'; | ||
import applyTransform, { | ||
camelToSnake, | ||
merge, | ||
mergeEach, | ||
notify, | ||
sanitize, | ||
snakeToCamel, | ||
starToSearch, | ||
} from '@webitel/ui-sdk/src/api/transformers'; | ||
import { TeamHookServiceApiFactory } from 'webitel-sdk'; | ||
import instance from '../../../../../../../app/api/instance'; | ||
import configuration from '../../../../../../../app/api/openAPIConfig'; | ||
|
||
const teamHookService = new TeamHookServiceApiFactory(configuration, '', instance); | ||
|
||
const fieldsToSend = ['event', 'properties', 'schema', 'enabled']; | ||
|
||
const preRequestHandler = (parentId) => (item) => ({ | ||
...item, | ||
teamId: parentId, | ||
}); | ||
|
||
const getTeamHooksList = async (params) => { | ||
const defaultObject = { | ||
enabled: false, | ||
}; | ||
|
||
const { | ||
page, | ||
size, | ||
search, | ||
sort, | ||
fields, | ||
id, | ||
parentId, | ||
} = applyTransform(params, [ | ||
merge(getDefaultGetParams()), | ||
starToSearch('search'), | ||
]); | ||
|
||
try { | ||
const response = await teamHookService.searchTeamHook( | ||
parentId, | ||
page, | ||
size, | ||
search, | ||
sort, | ||
fields, | ||
id, | ||
); | ||
const { items, next } = applyTransform(response.data, [ | ||
snakeToCamel(), | ||
merge(getDefaultGetListResponse()), | ||
]); | ||
return { | ||
items: applyTransform(items, [ | ||
mergeEach(defaultObject), | ||
]), | ||
next, | ||
}; | ||
} catch (err) { | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
const getTeamHook = async ({ parentId, itemId: id }) => { | ||
const defaultObject = { | ||
event: '', | ||
properties: [], | ||
schema: {}, | ||
enabled: false, | ||
}; | ||
|
||
try { | ||
const response = await teamHookService.readTeamHook(parentId, id); | ||
return applyTransform(response.data, [ | ||
snakeToCamel(), | ||
merge(defaultObject), | ||
]); | ||
} catch (err) { | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
const addTeamHook = async ({ parentId, itemInstance }) => { | ||
const item = applyTransform(itemInstance, [ | ||
preRequestHandler(parentId), | ||
sanitize(fieldsToSend), | ||
camelToSnake(), | ||
]); | ||
try { | ||
const response = await teamHookService.createTeamHook(parentId, item); | ||
return applyTransform(response.data, [ | ||
snakeToCamel(), | ||
]); | ||
} catch (err) { | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
const patchTeamHook = async ({ changes, id, parentId }) => { | ||
const body = applyTransform(changes, [ | ||
sanitize(fieldsToSend), | ||
camelToSnake(), | ||
]); | ||
|
||
try { | ||
const response = await teamHookService.patchTeamHook(parentId, id, body); | ||
return applyTransform(response.data, [ | ||
snakeToCamel(), | ||
]); | ||
} catch (err) { | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
const updateTeamHook = async ({ itemInstance, itemId: id, parentId }) => { | ||
const item = applyTransform(itemInstance, [ | ||
preRequestHandler(parentId), | ||
sanitize(fieldsToSend), | ||
camelToSnake(), | ||
]); | ||
try { | ||
const response = await teamHookService.updateTeamHook(parentId, id, item); | ||
return applyTransform(response.data, [ | ||
snakeToCamel(), | ||
]); | ||
} catch (err) { | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
const deleteTeamHook = async ({ parentId, id }) => { | ||
try { | ||
const response = await teamHookService.deleteTeamHook(parentId, id); | ||
return applyTransform(response.data, []); | ||
} catch (err) { | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
const TeamHooksAPI = { | ||
getList: getTeamHooksList, | ||
get: getTeamHook, | ||
add: addTeamHook, | ||
patch: patchTeamHook, | ||
update: updateTeamHook, | ||
delete: deleteTeamHook, | ||
}; | ||
|
||
export default TeamHooksAPI; |
103 changes: 103 additions & 0 deletions
103
...modules/contact-center/modules/teams/modules/hooks/components/opened-team-hooks-popup.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,103 @@ | ||
<template> | ||
<wt-popup | ||
min-width="480" | ||
overflow | ||
@close="close" | ||
> | ||
<template #title> | ||
{{ $tc('objects.ccenter.queues.hooks.hooks', 1) }} | ||
</template> | ||
<template #main> | ||
<form> | ||
<wt-select | ||
:value="event" | ||
:clearable="false" | ||
:label="$t('objects.ccenter.queues.hooks.event')" | ||
:options="eventOptions" | ||
:v="v$.itemInstance.event" | ||
required | ||
track-by="value" | ||
@input="setItemProp({ prop: 'event', value: $event.value })" | ||
/> | ||
<wt-select | ||
:clearable="false" | ||
:label="$tc('objects.routing.flow.flow', 1)" | ||
:search-method="loadFlowOptions" | ||
:v="v$.itemInstance.schema" | ||
:value="itemInstance.schema" | ||
required | ||
@input="setItemProp({ prop: 'schema', value: $event })" | ||
/> | ||
</form> | ||
</template> | ||
<template #actions> | ||
<wt-button | ||
:disabled="disabledSave" | ||
@click="save" | ||
> | ||
{{ $t('objects.save') }} | ||
</wt-button> | ||
<wt-button | ||
color="secondary" | ||
@click="close" | ||
> | ||
{{ $t('objects.close') }} | ||
</wt-button> | ||
</template> | ||
</wt-popup> | ||
</template> | ||
|
||
<script> | ||
import { EngineRoutingSchemaType } from 'webitel-sdk'; | ||
import { snakeToCamel } from '@webitel/ui-sdk/src/scripts/caseConverters'; | ||
import { useVuelidate } from '@vuelidate/core'; | ||
import { required } from '@vuelidate/validators'; | ||
import nestedObjectMixin from '../../../../../../../app/mixins/objectPagesMixins/openedObjectMixin/nestedObjectMixin'; | ||
import FlowsAPI from '../../../../../../routing/modules/flow/api/flow'; | ||
import HookEvent from '../enum/HookTeamEvent.enum'; | ||
export default { | ||
name: 'OpenedQueueHooksPopup', | ||
mixins: [nestedObjectMixin], | ||
setup: () => ({ | ||
v$: useVuelidate(), | ||
}), | ||
data: () => ({ | ||
namespace: 'ccenter/teams/hooks', | ||
}), | ||
validations: { | ||
itemInstance: { | ||
event: { required }, | ||
schema: { required }, | ||
}, | ||
}, | ||
computed: { | ||
eventOptions() { | ||
return Object.values(HookEvent).map((event) => ({ | ||
name: this.$t(`objects.ccenter.teams.hooks.eventTypes.${this.snakeToCamel(event)}`), | ||
value: event, | ||
})); | ||
}, | ||
event() { | ||
const { event } = this.itemInstance; | ||
return event ? { | ||
name: this.$t(`objects.ccenter.teams.hooks.eventTypes.${this.snakeToCamel(event)}`), | ||
value: event, | ||
} : {}; | ||
} | ||
}, | ||
methods: { | ||
loadFlowOptions(params) { | ||
return FlowsAPI.getLookup({ ...params, type: [EngineRoutingSchemaType.Service] }); | ||
}, | ||
snakeToCamel, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
</style> |
Oops, something went wrong.