Skip to content

Commit

Permalink
Merge pull request #23 from webitel/feat/contact-timezone
Browse files Browse the repository at this point in the history
feat: contact timezone [WTEL-3707]
  • Loading branch information
dlohvinov authored Oct 3, 2023
2 parents b10120d + c0c9a6f commit 8509718
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
18 changes: 9 additions & 9 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 @@ -20,7 +20,7 @@
"vue-i18n": "^9.2.2",
"vue-router": "^4.0.3",
"vuex": "^4.0.0",
"webitel-sdk": "^23.7.13"
"webitel-sdk": "^23.9.5"
},
"devDependencies": {
"@babel/core": "^7.12.16",
Expand Down
13 changes: 11 additions & 2 deletions src/modules/contacts/api/ContactsAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const getList = async (params) => {
};

const get = async ({ itemId: id }) => {
const fields = ['name', 'about', 'labels', 'etag', 'mode', 'managers'];
const fields = ['name', 'about', 'labels', 'etag', 'mode', 'managers', 'timezones'];

const defaultObject = {};
const itemResponseHandler = (item) => {
Expand All @@ -118,7 +118,7 @@ const get = async ({ itemId: id }) => {
}
};

const fieldsToSend = ['name', 'labels', 'about', 'managers'];
const fieldsToSend = ['name', 'labels', 'about', 'managers', 'timezones'];

const sanitizeManagers = (itemInstance) => {
// handle many managers and even no managers field cases
Expand All @@ -127,9 +127,17 @@ const sanitizeManagers = (itemInstance) => {
return { ...itemInstance, managers };
};

const sanitizeTimezones = (itemInstance) => {
// handle many timezones and even no timezones field cases
const timezones = (itemInstance.timezones ||
[]).filter(({ timezone } = {}) => timezone.id);
return { ...itemInstance, timezones };
};

const add = async ({ itemInstance }) => {
const item = applyTransform(itemInstance, [
sanitizeManagers,
sanitizeTimezones,
sanitize(fieldsToSend),
camelToSnake(),

Expand All @@ -150,6 +158,7 @@ const update = async ({ itemInstance }) => {
const { etag } = itemInstance;
const item = applyTransform(itemInstance, [
sanitizeManagers,
sanitizeTimezones,
sanitize(fieldsToSend),
camelToSnake(),
]);
Expand Down
10 changes: 10 additions & 0 deletions src/modules/contacts/api/TimezonesAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const getList = async (params) => {
page,
size,
search,
sort,
fields,
} = applyTransform(params, [
merge(getDefaultGetParams()),
starToSearch('search'),
Expand All @@ -28,6 +30,8 @@ const getList = async (params) => {
page,
size,
search,
sort,
fields,
);
const { items, next } = applyTransform(response.data, [
snakeToCamel(),
Expand All @@ -44,8 +48,14 @@ const getList = async (params) => {
}
};

const getLookup = (params) => getList({
...params,
fields: params.fields || ['id', 'name'],
});

const TimezonesAPI = {
getList,
getLookup,
};

export default TimezonesAPI;
6 changes: 3 additions & 3 deletions src/modules/contacts/components/contact-popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
@input="draft.name.commonName = $event"
></wt-input>
<wt-select
:value="draft.timezones"
:value="draft.timezones[0]?.timezone"
:label="t('date.timezone', 1)"
:search-method="TimezonesAPI.getList"
@input="draft.timezones = $event"
:search-method="TimezonesAPI.getLookup"
@input="draft.timezones[0] = { timezone: $event }"
></wt-select>
<wt-select
:value="draft.managers[0]?.user"
Expand Down
2 changes: 1 addition & 1 deletion src/modules/contacts/components/opened-contact-general.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<p class="opened-contact-general-item__title">
{{ t('date.timezone', 1) }}
</p>
<p class="opened-contact-general-item__value">{{ timezones[0] }}</p>
<p class="opened-contact-general-item__value">{{ timezones[0].timezone.name }}</p>
</div>

<wt-divider v-if="timezones.length"></wt-divider>
Expand Down

0 comments on commit 8509718

Please sign in to comment.