feat: save language to BE

This commit is contained in:
lleohao
2024-09-10 08:52:52 +00:00
parent 637cd15ab4
commit 49900050f7
10 changed files with 48 additions and 29 deletions

View File

@ -2,14 +2,19 @@ import { useAtom } from "jotai";
import { currentUserAtom } from "@/features/user/atoms/current-user-atom";
import React, { useEffect } from "react";
import useCurrentUser from "@/features/user/hooks/use-current-user";
import { useTranslation } from "react-i18next";
export function UserProvider({ children }: React.PropsWithChildren) {
const [, setCurrentUser] = useAtom(currentUserAtom);
const { data, isLoading, error } = useCurrentUser();
const { i18n } = useTranslation();
useEffect(() => {
if (data && data.user && data.workspace) {
setCurrentUser(data);
i18n.changeLanguage(
data.user?.settings?.preferences?.language || "en-US",
);
}
}, [data, isLoading]);