From 65bbd0768cd77697cf1422bbd3452ad4d53d0a79 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 23 Jan 2025 15:09:38 +0100 Subject: [PATCH] feat: refs #7984 add currency in userPanel --- src/components/UserPanel.vue | 17 +++++++++++++++++ src/components/ui/VnCurrency.vue | 10 +++++++--- src/composables/useSession.js | 3 ++- src/composables/useState.js | 1 + src/i18n/locale/en.yml | 1 + src/i18n/locale/es.yml | 1 + 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/components/UserPanel.vue b/src/components/UserPanel.vue index 5f3266eb2..3937c803e 100644 --- a/src/components/UserPanel.vue +++ b/src/components/UserPanel.vue @@ -47,6 +47,8 @@ const darkMode = computed({ }, }); +const foreignCurrency = ref(); + const user = state.getUser(); const warehousesData = ref(); const companiesData = ref(); @@ -58,6 +60,8 @@ onMounted(async () => { }); function updatePreferences() { + foreignCurrency.value = user.value.foreignCurrency; + if (user.value.darkMode !== null) { darkMode.value = user.value.darkMode; } @@ -116,6 +120,11 @@ async function saveUserData(param, value) { } } +async function saveCurrency(value) { + user.value.foreignCurrency = value; + useState().setUser(user.value); +} + const onDataSaved = () => { notify('globals.dataSaved', 'positive'); }; @@ -169,6 +178,14 @@ const onDataError = () => { color="primary" unchecked-icon="light_mode" /> + diff --git a/src/components/ui/VnCurrency.vue b/src/components/ui/VnCurrency.vue index b3ea821fd..13ea6aaf3 100644 --- a/src/components/ui/VnCurrency.vue +++ b/src/components/ui/VnCurrency.vue @@ -2,6 +2,7 @@ import { toCurrency } from 'src/filters'; import { computed, onMounted, ref } from 'vue'; import { useArrayData } from 'src/composables/useArrayData'; +import { useState } from 'src/composables/useState'; const $props = defineProps({ model: { @@ -28,6 +29,9 @@ const $props = defineProps({ }, }); +const state = useState(); +const user = state.getUser(); + const foreignFieldComputed = ref(); const arrayData = $props.arrayDataModel && useArrayData($props.arrayDataModel); const foreignValue = ref(); @@ -61,8 +65,8 @@ function getLabel() { diff --git a/src/composables/useSession.js b/src/composables/useSession.js index e69819a68..4d251f0e5 100644 --- a/src/composables/useSession.js +++ b/src/composables/useSession.js @@ -60,7 +60,7 @@ export function useSession() { const { data: isValidToken } = await axios.get('VnUsers/validateToken'); if (isValidToken) destroyTokenPromises = Object.entries(tokens).map(([key, url]) => - destroyToken(url, storage, key) + destroyToken(url, storage, key), ); } } finally { @@ -75,6 +75,7 @@ export function useSession() { nickname: '', lang: '', darkMode: null, + foreignCurrency: true, }); stopRenewer(); diff --git a/src/composables/useState.js b/src/composables/useState.js index c2ac1740c..04e5463fe 100644 --- a/src/composables/useState.js +++ b/src/composables/useState.js @@ -10,6 +10,7 @@ const user = ref({ darkMode: null, companyFk: null, warehouseFk: null, + foreignCurrency: true, }); if (sessionStorage.getItem('user')) user.value = JSON.parse(sessionStorage.getItem('user')); diff --git a/src/i18n/locale/en.yml b/src/i18n/locale/en.yml index 0ec63283f..3d19b787d 100644 --- a/src/i18n/locale/en.yml +++ b/src/i18n/locale/en.yml @@ -2,6 +2,7 @@ globals: lang: es: Spanish en: English + foreignCurrency: Foreign currency quantity: Quantity language: Language entity: Entity diff --git a/src/i18n/locale/es.yml b/src/i18n/locale/es.yml index 447f792ab..d1a5b4c5b 100644 --- a/src/i18n/locale/es.yml +++ b/src/i18n/locale/es.yml @@ -2,6 +2,7 @@ globals: lang: es: Español en: Inglés + foreignCurrency: Moneda extranjera language: Idioma quantity: Cantidad entity: Entidad