mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Change language on save instead of on restart
This commit is contained in:
@@ -164,14 +164,14 @@
|
||||
import { defineComponent, computed, toRefs, ref, watch } from '@vue/composition-api';
|
||||
|
||||
import UsersNavigation from '../components/navigation.vue';
|
||||
import { i18n } from '@/lang';
|
||||
import { i18n, setLanguage } from '@/lang';
|
||||
import router from '@/router';
|
||||
import RevisionsDrawerDetail from '@/views/private/components/revisions-drawer-detail';
|
||||
import CommentsSidebarDetail from '@/views/private/components/comments-sidebar-detail';
|
||||
import useItem from '@/composables/use-item';
|
||||
import SaveOptions from '@/views/private/components/save-options';
|
||||
import api from '@/api';
|
||||
import { useFieldsStore, useUserStore } from '@/stores/';
|
||||
import { useFieldsStore, useCollectionsStore, useUserStore } from '@/stores/';
|
||||
import useFormFields from '@/composables/use-form-fields';
|
||||
import { Field } from '@/types';
|
||||
import UserInfoSidebarDetail from '../components/user-info-sidebar-detail.vue';
|
||||
@@ -213,6 +213,7 @@ export default defineComponent({
|
||||
setup(props) {
|
||||
const form = ref<HTMLElement>();
|
||||
const fieldsStore = useFieldsStore();
|
||||
const collectionsStore = useCollectionsStore();
|
||||
const userStore = useUserStore();
|
||||
|
||||
const { primaryKey } = toRefs(props);
|
||||
@@ -350,13 +351,15 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
async function saveAndQuit() {
|
||||
await save();
|
||||
const savedItem: Record<string, any> = await save();
|
||||
await setLang(savedItem);
|
||||
await refreshCurrentUser();
|
||||
router.push(`/users`);
|
||||
}
|
||||
|
||||
async function saveAndStay() {
|
||||
const savedItem: Record<string, any> = await save();
|
||||
await setLang(savedItem);
|
||||
|
||||
revisionsDrawerDetail.value?.$data?.refresh?.();
|
||||
|
||||
@@ -368,7 +371,8 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
async function saveAndAddNew() {
|
||||
await save();
|
||||
const savedItem: Record<string, any> = await save();
|
||||
await setLang(savedItem);
|
||||
await refreshCurrentUser();
|
||||
router.push(`/users/+`);
|
||||
}
|
||||
@@ -383,6 +387,17 @@ export default defineComponent({
|
||||
router.push(`/users`);
|
||||
}
|
||||
|
||||
async function setLang(user: Record<string, any>) {
|
||||
const newLang = user?.language;
|
||||
|
||||
if (newLang && newLang !== i18n.locale) {
|
||||
await setLanguage(newLang);
|
||||
|
||||
await fieldsStore.hydrate();
|
||||
await collectionsStore.hydrate();
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshCurrentUser() {
|
||||
if (userStore.state.currentUser!.id === item.value?.id) {
|
||||
await userStore.hydrate();
|
||||
|
||||
Reference in New Issue
Block a user