diff --git a/src/components/UserPanel.vue b/src/components/UserPanel.vue index 98334460a..810f63044 100644 --- a/src/components/UserPanel.vue +++ b/src/components/UserPanel.vue @@ -13,12 +13,14 @@ import FetchData from 'components/FetchData.vue'; import { useClipboard } from 'src/composables/useClipboard'; import { useRole } from 'src/composables/useRole'; import VnAvatar from './ui/VnAvatar.vue'; +import useNotify from 'src/composables/useNotify'; const state = useState(); const session = useSession(); const router = useRouter(); const { t, locale } = useI18n(); const { copyText } = useClipboard(); +const { notify } = useNotify(); const userLocale = computed({ get() { @@ -53,6 +55,7 @@ const user = state.getUser(); const warehousesData = ref(); const companiesData = ref(); const accountBankData = ref(); +const isEmployee = computed(() => useRole().isEmployee()); onMounted(async () => { updatePreferences(); @@ -70,18 +73,28 @@ function updatePreferences() { async function saveDarkMode(value) { const query = `/UserConfigs/${user.value.id}`; - await axios.patch(query, { - darkMode: value, - }); - user.value.darkMode = value; + try { + await axios.patch(query, { + darkMode: value, + }); + user.value.darkMode = value; + onDataSaved(); + } catch (error) { + onDataError(); + } } async function saveLanguage(value) { const query = `/VnUsers/${user.value.id}`; - await axios.patch(query, { - lang: value, - }); - user.value.lang = value; + try { + await axios.patch(query, { + lang: value, + }); + user.value.lang = value; + onDataSaved(); + } catch (error) { + onDataError(); + } } function logout() { @@ -97,11 +110,23 @@ function localUserData() { state.setUser(user.value); } -function saveUserData(param, value) { - axios.post('UserConfigs/setUserConfig', { [param]: value }); - localUserData(); +async function saveUserData(param, value) { + try { + await axios.post('UserConfigs/setUserConfig', { [param]: value }); + localUserData(); + onDataSaved(); + } catch (error) { + onDataError(); + } } -const isEmployee = computed(() => useRole().isEmployee()); + +const onDataSaved = () => { + notify('globals.dataSaved', 'positive'); +}; + +const onDataError = () => { + notify('errors.updateUserConfig', 'negative'); +};