forked from verdnatura/hedera-web
Integrate update config language dropdown
This commit is contained in:
parent
2758dcf2c8
commit
f1a8fd2710
|
@ -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>
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue