-
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 12 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,117 @@ | ||
<template> | ||
<section class="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. клас має завжди відповідати назві компонента |
||
<header class="content-header"> | ||
<h3 class="content-title"> | ||
{{ $t('settings.ringtones.title') }} | ||
</h3> | ||
</header> | ||
<form> | ||
<div class="ringtone__wrapper"> | ||
<wt-checkbox | ||
:selected="isCustomRingtone" | ||
:label="$tc('settings.ringtones.customRingtone')" | ||
@change="selectRingtoneType" | ||
/> | ||
<wt-select | ||
v-model="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. в-модел краще не використовувати. чому? -- писав про це в нашому чаті |
||
: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, | ||
ringtone: {}, | ||
options: [], | ||
}), | ||
computed: { | ||
ringtone: { | ||
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.ringtone; | ||
}, | ||
set(value) { | ||
this.ringtone = value; | ||
}, | ||
}, | ||
isRingtoneSelected() { | ||
return this.isCustomRingtone && this.ringtone.name; | ||
}, | ||
audioLink() { | ||
return this.isRingtoneSelected | ||
? `${import.meta.env.VITE_RINGTONES_URL}/${this.ringtone.name}` | ||
: ''; | ||
}, | ||
}, | ||
methods: { | ||
selectRingtoneType() { | ||
this.isCustomRingtone = !this.isCustomRingtone; | ||
if (!this.isRingtoneSelected) this.ringtone = {}; | ||
}, | ||
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.ringtone.name | ||
? localStorage.setItem('ringtone', this.ringtone.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.ringtone = this.options.find(item => item.name === ringtoneName); | ||
this.isCustomRingtone = true; | ||
} | ||
}, | ||
}, | ||
async mounted() { | ||
try { | ||
await this.loadRingtonesOptions(); | ||
this.restoreRingtone(); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}, | ||
|
||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.ringtone__wrapper { | ||
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> | ||
|
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.
мені теж
але тоді треба шукати як пофіксити біом)