mirror of
https://github.com/docmost/docmost.git
synced 2025-11-16 14:41:08 +10:00
feat: save language to locale column
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
import { Group, Text, Select } from "@mantine/core";
|
import { Group, Text, Select } from "@mantine/core";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { updateUser } from "../services/user-service";
|
import { updateUser } from "../services/user-service";
|
||||||
import { IUser } from "../types/user.types";
|
|
||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { userAtom } from "../atoms/current-user-atom";
|
import { userAtom } from "../atoms/current-user-atom";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
@ -26,11 +25,11 @@ function LanguageSwitcher() {
|
|||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
const [user, setUser] = useAtom(userAtom);
|
const [user, setUser] = useAtom(userAtom);
|
||||||
const [language, setLanguage] = useState(
|
const [language, setLanguage] = useState(
|
||||||
user.settings?.preferences?.language || "en-US",
|
user?.locale === "en" ? "en-US" : user.locale,
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleChange = async (value: string) => {
|
const handleChange = async (value: string) => {
|
||||||
const updatedUser = await updateUser({ language: value });
|
const updatedUser = await updateUser({ locale: value });
|
||||||
|
|
||||||
setLanguage(value);
|
setLanguage(value);
|
||||||
setUser(updatedUser);
|
setUser(updatedUser);
|
||||||
@ -52,4 +51,3 @@ function LanguageSwitcher() {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,6 @@
|
|||||||
import { IWorkspace } from "@/features/workspace/types/workspace.types";
|
import { IWorkspace } from "@/features/workspace/types/workspace.types";
|
||||||
|
|
||||||
type IUserPreferences = {
|
export interface IUser {
|
||||||
fullPageWidth: boolean;
|
|
||||||
language: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface IUser extends IUserPreferences {
|
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
email: string;
|
email: string;
|
||||||
@ -16,12 +11,14 @@ export interface IUser extends IUserPreferences {
|
|||||||
invitedById: string;
|
invitedById: string;
|
||||||
lastLoginAt: string;
|
lastLoginAt: string;
|
||||||
lastActiveAt: Date;
|
lastActiveAt: Date;
|
||||||
|
locale: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
role: string;
|
role: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
deactivatedAt: Date;
|
deactivatedAt: Date;
|
||||||
deletedAt: Date;
|
deletedAt: Date;
|
||||||
|
fullPageWidth: boolean; // used for update
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICurrentUser {
|
export interface ICurrentUser {
|
||||||
@ -30,5 +27,7 @@ export interface ICurrentUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IUserSettings {
|
export interface IUserSettings {
|
||||||
preferences: IUserPreferences
|
preferences: {
|
||||||
|
fullPageWidth: boolean;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export function UserProvider({ children }: React.PropsWithChildren) {
|
|||||||
if (data && data.user && data.workspace) {
|
if (data && data.user && data.workspace) {
|
||||||
setCurrentUser(data);
|
setCurrentUser(data);
|
||||||
i18n.changeLanguage(
|
i18n.changeLanguage(
|
||||||
data.user?.settings?.preferences?.language || "en-US",
|
data.user.locale === "en" ? "en-US" : data.user.locale,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [data, isLoading]);
|
}, [data, isLoading]);
|
||||||
|
|||||||
@ -15,5 +15,5 @@ export class UpdateUserDto extends PartialType(
|
|||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
language: string;
|
locale: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,13 +33,6 @@ export class UserService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof updateUserDto.language !== 'undefined') {
|
|
||||||
return this.updateUserLanguagePreference(
|
|
||||||
userId,
|
|
||||||
updateUserDto.language,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateUserDto.name) {
|
if (updateUserDto.name) {
|
||||||
user.name = updateUserDto.name;
|
user.name = updateUserDto.name;
|
||||||
}
|
}
|
||||||
@ -55,6 +48,10 @@ export class UserService {
|
|||||||
user.avatarUrl = updateUserDto.avatarUrl;
|
user.avatarUrl = updateUserDto.avatarUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (updateUserDto.locale) {
|
||||||
|
user.locale = updateUserDto.locale;
|
||||||
|
}
|
||||||
|
|
||||||
await this.userRepo.updateUser(updateUserDto, userId, workspaceId);
|
await this.userRepo.updateUser(updateUserDto, userId, workspaceId);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
@ -66,8 +63,4 @@ export class UserService {
|
|||||||
fullPageWidth,
|
fullPageWidth,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateUserLanguagePreference(userId: string, language: string) {
|
|
||||||
return this.userRepo.updatePreference(userId, 'language', language);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user