Integrate update config language dropdown
gitea/hedera-web/pipeline/pr-4922-vueMigration There was a failure building this commit Details

This commit is contained in:
William Buezas 2024-09-13 21:42:40 -03:00
parent 2758dcf2c8
commit f1a8fd2710
2 changed files with 15 additions and 5 deletions

View File

@ -99,7 +99,9 @@ onMounted(() => fetchLanguagesSql());
option-label="name" option-label="name"
option-value="code" option-value="code"
:options="langOptions" :options="langOptions"
@update:model-value="vnFormRef.submit()" @update:model-value="
userStore.updateUserLang(data.lang)
"
/> />
</template> </template>
<template #extraForm> <template #extraForm>

View File

@ -1,8 +1,10 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { api, jApi } from 'boot/axios'; import { api, jApi } from 'boot/axios';
import { i18n } from 'src/boot/i18n'; import { i18n } from 'src/boot/i18n';
import useNotify from 'src/composables/useNotify.js';
const { t } = i18n.global; const { t } = i18n.global;
const { notify } = useNotify();
export const useUserStore = defineStore('user', { export const useUserStore = defineStore('user', {
state: () => { state: () => {
@ -27,15 +29,15 @@ export const useUserStore = defineStore('user', {
getters: { getters: {
loggedIn: state => state.token != null, loggedIn: state => state.token != null,
userLang: state => userLocaleOption: state =>
state.localeOptions?.find(l => l.value === state?.user?.lang)?.lang state.localeOptions?.find(l => l.value === state?.user?.lang)
}, },
actions: { actions: {
async init() { async init() {
await this.fetchUser(); await this.fetchUser();
await this.supplantInit(); await this.supplantInit();
i18n.global.locale.value = this.userLang || 'en-US'; this.updateSiteLocale();
}, },
async getToken() { async getToken() {
@ -105,8 +107,12 @@ export const useUserStore = defineStore('user', {
await this.fetchUser(); await this.fetchUser();
}, },
updateSiteLocale(locale = null) {
i18n.global.locale.value =
locale || this.userLocaleOption.lang || 'en-US';
},
async updateUserLang(lang) { async updateUserLang(lang) {
console.log('lang to update: ', lang);
if (!this.user || this.user.lang === lang) return; if (!this.user || this.user.lang === lang) return;
await jApi.execQuery( await jApi.execQuery(
`START TRANSACTION; `START TRANSACTION;
@ -116,6 +122,8 @@ export const useUserStore = defineStore('user', {
{ id: this.user.id, lang } { id: this.user.id, lang }
); );
this.user.lang = lang; this.user.lang = lang;
this.updateSiteLocale();
notify(t('dataSaved'), 'positive');
} }
} }
}); });