-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/custom ringtone [WTEL-4348] #706
Changes from 10 commits
7143d58
296051b
5b6ceac
30079f3
31d1da0
b54fdc2
e529f79
b53a6f4
6e1082b
edc24e1
ef8fc9b
7f73be1
6da59ee
9425771
2e37a98
bb2ad0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import instance from '../../../app/api/instance'; | ||
import applyTransform, { | ||
camelToSnake, | ||
notify, | ||
snakeToCamel, | ||
} from '@webitel/ui-sdk/src/api/transformers'; | ||
import instance from '../../../app/api/instance'; | ||
|
||
const baseUrl = 'users'; | ||
|
||
|
@@ -12,47 +12,76 @@ export const getWebPhone = async () => { | |
|
||
try { | ||
const response = await instance.get(url); | ||
return applyTransform(response.data, [snakeToCamel()]); | ||
return applyTransform(response.data, [ | ||
snakeToCamel(), | ||
]); | ||
} catch (err) { | ||
if (err.response.status === 404) return; | ||
// phone settings doesn't exist on backend if user is new, and we have to hide notification about this error | ||
// https://webitel.atlassian.net/browse/WTEL-4346 | ||
throw applyTransform(err, [notify]); | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
export const changeWebPhone = async (changes) => { | ||
const item = applyTransform(changes, [camelToSnake()]); | ||
|
||
const item = applyTransform(changes, [ | ||
camelToSnake(), | ||
]); | ||
|
||
const url = 'user/settings/phone'; | ||
|
||
try { | ||
const response = await instance.put(url, item); | ||
return applyTransform(response.data, [snakeToCamel()]); | ||
return applyTransform(response.data, [ | ||
snakeToCamel(), | ||
]); | ||
} catch (err) { | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
export const getRingtonesList = async () => { | ||
try { | ||
const ringtones = await fetch(`${import.meta.env.VITE_RINGTONES_URL}/index.json`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Я не впевнена що треба саме виносити у env, бо він більше включає загальні змінні для перевикористання There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Даня в описі до задачі просто писав, шо тре There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. треба, бо це за межами апплікейшена |
||
.then((res) => res.json()); | ||
return ringtones.ringtones; | ||
} catch (err) { | ||
throw applyTransform(err, [notify]); | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
const patchItem = async ({ changes, id }) => { | ||
const body = applyTransform(changes, [camelToSnake()]); | ||
const body = applyTransform(changes, [ | ||
camelToSnake(), | ||
]); | ||
const url = `${baseUrl}/${id}`; | ||
try { | ||
const response = await instance.patch(url, body); | ||
return applyTransform(response.data, [snakeToCamel()]); | ||
return applyTransform(response.data, [ | ||
snakeToCamel(), | ||
]); | ||
} catch (err) { | ||
throw applyTransform(err, [notify]); | ||
throw applyTransform(err, [ | ||
notify, | ||
]); | ||
} | ||
}; | ||
|
||
export const changePassword = ({ id, changes }) => | ||
patchItem({ | ||
id, | ||
changes, | ||
}); | ||
export const changePassword = ({ id, changes }) => patchItem({ | ||
id, | ||
changes, | ||
}); | ||
|
||
export default { | ||
changePassword, | ||
changeWebPhone, | ||
getWebPhone, | ||
getRingtonesList, | ||
}; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а чого the-ringtone, а не, скажімо, custom-ringtone? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<template> | ||
<section class="settings-section__setting"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Клас цей тут не потрібен, а як потрібен - називаємо як компонент) |
||
<header class="content-header"> | ||
<h3 class="content-title"> | ||
{{ $t('settings.ringtones.title') }} | ||
</h3> | ||
</header> | ||
<form> | ||
<div class="settings-section__wrapper"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а дів тут точно потрібен? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. так |
||
<wt-checkbox | ||
v-model="isCustomRingtone" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. з велью не працює, працює з :selected. змінила |
||
:label="$tc('settings.ringtones.customRingtone')" | ||
@change="selectRingtoneType" | ||
/> | ||
<wt-select | ||
v-model="currentRingtone" | ||
:options="options" | ||
:disabled="!isCustomRingtone" | ||
:clearable="false" | ||
:label="$tc('settings.ringtones.ringtone')" | ||
option-label="label" | ||
track-by="label" | ||
/> | ||
<wt-player | ||
v-show="audioLink" | ||
:src="audioLink" | ||
:closable="false" | ||
:autoplay="false" | ||
/> | ||
<wt-button | ||
@click.prevent="saveRingtone" | ||
> | ||
{{ $t('objects.save') }} | ||
</wt-button> | ||
</div> | ||
</form> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
import { useVuelidate } from '@vuelidate/core'; | ||
import { getRingtonesList } from '../api/settings'; | ||
|
||
export default { | ||
name: 'TheRingtone', | ||
setup: () => ({ | ||
v$: useVuelidate(), | ||
}), | ||
data: () => ({ | ||
isCustomRingtone: false, | ||
currentRingtone: {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. може просто ringtone? |
||
options: [], | ||
}), | ||
computed: { | ||
currentRingtone: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а чому саме get/set потрібен? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. я досить довго проколупалась з тим, що "звичними способами" не працює. Схоже, через те, що ми в данному випадку оперуємо об'єктами, а не простими типами данних. |
||
get() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. все таки не розумію навіщо гетер/сетер( |
||
return this.currentRingtone; | ||
}, | ||
set(value) { | ||
this.currentRingtone = value; | ||
}, | ||
}, | ||
audioLink() { | ||
return this.currentRingtone.name && this.isCustomRingtone ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Умова повторюється, давай її у компьютед) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. зробила |
||
`${import.meta.env.VITE_RINGTONES_URL}${this.currentRingtone.name}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. може /? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. точно, дякую! |
||
: ''; | ||
}, | ||
}, | ||
async mounted() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mounted нижче методів) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. та наче ні... методи внизу, маунтед зверху There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. поміняла) мені чогось всю дорогу здавалось, що навпаки |
||
try { | ||
await this.loadRingtonesOptions(); | ||
this.restoreRingtone(); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}, | ||
methods: { | ||
selectRingtoneType() { | ||
if (this.isCustomRingtone && this.currentRingtone.name) this.currentRingtone = {}; | ||
}, | ||
saveRingtone() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. saveRingtoneInLocalStorage? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а нашо? якщо ми просто зберігаємо рінгтон, у нас немає інших типів збереження тут наразі, щоб ми могли з чимось сплутати |
||
this.currentRingtone.name | ||
? localStorage.setItem('ringtone', this.currentRingtone.name) | ||
: localStorage.removeItem('ringtone'); | ||
}, | ||
async loadRingtonesOptions() { | ||
this.options = await getRingtonesList(); | ||
}, | ||
restoreRingtone() { | ||
const ringtoneName = localStorage.getItem('ringtone'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Я думаю якщо в локалСторадж ти зберігаєш тільки імя - то може і ключ назвати ringtone-name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Чесно кажучи, не бачу сенсу називати в локал стореджі ringtoneName There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. треба |
||
if (ringtoneName) { | ||
this.currentRingtone = this.options.find(item => item.name === ringtoneName); | ||
this.isCustomRingtone = true; | ||
} | ||
}, | ||
}, | ||
|
||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.settings-section__wrapper { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Давай адаптуємо назви классів до назви компонента) |
||
display: flex; | ||
flex-direction: column; | ||
gap: var(--spacing-sm); | ||
} | ||
|
||
.wt-button { | ||
display: block; | ||
margin: 3px 0 0 auto; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а шо це за 3 пікселі затіхарілісь?)) |
||
} | ||
</style> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ | |
</div> | ||
</form> | ||
</section> | ||
<the-ringtone class="settings-section__setting" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Розберись будь ласочка з цим классом) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Насправді, в сеттінгах є цей класс |
||
</section> | ||
</template> | ||
</wt-page-wrapper> | ||
|
@@ -93,10 +94,12 @@ import { useVuelidate } from '@vuelidate/core'; | |
import { required, sameAs } from '@vuelidate/validators'; | ||
import getNamespacedState from '@webitel/ui-sdk/src/store/helpers/getNamespacedState'; | ||
import { mapState } from 'vuex'; | ||
import { changePassword, changeWebPhone, getWebPhone } from '../api/settings'; | ||
import { changePassword, changeWebPhone, getWebPhone, getRingtonesList } from '../api/settings'; | ||
import TheRingtone from './the-ringtone.vue'; | ||
|
||
export default { | ||
name: 'TheSettings', | ||
components: { TheRingtone }, | ||
inject: ['$eventBus'], | ||
|
||
setup: () => ({ | ||
|
@@ -251,7 +254,7 @@ export default { | |
} | ||
|
||
&__switcher { | ||
margin-bottom: var(--spacing-xs); | ||
margin-bottom: var(--spacing-sm); | ||
} | ||
} | ||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я так зрозуміла, що це біом сплюскує отак applyTransform, а я його, виходить, заново "росправила"
мені, насправді, так не подобається як воно в одну строчку виглядає...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
мені теж
але тоді треба шукати як пофіксити біом)