From a5c6d628ca9eb4378cd548e4a4d9b79bc554592e Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 23 Sep 2024 18:48:58 +0000 Subject: [PATCH] feat: enable notify positive when user update self data --- src/components/UserPanel.vue | 43 +++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/components/UserPanel.vue b/src/components/UserPanel.vue index 98334460a..5276f9e20 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; + notify('globals.dataSaved', 'positive'); + } catch (error) { + console.error(error); + } } 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; + notify('globals.dataSaved', 'positive'); + } catch (error) { + console.error(error); + } } function logout() { @@ -98,10 +111,18 @@ function localUserData() { } function saveUserData(param, value) { - axios.post('UserConfigs/setUserConfig', { [param]: value }); - localUserData(); + try { + axios.post('UserConfigs/setUserConfig', { [param]: value }); + localUserData(); + notify('globals.dataSaved', 'positive'); + } catch (error) { + console.error(error); + } } -const isEmployee = computed(() => useRole().isEmployee()); + +const onDataSaved = () => { + notify('globals.dataSaved', 'positive'); +};