0
1
Fork 0

Integrate update config language dropdown

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-value="code"
:options="langOptions"
@update:model-value="vnFormRef.submit()"
@update:model-value="
userStore.updateUserLang(data.lang)
"
/>
</template>
<template #extraForm>

View File

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