quivr/frontend/app/user/page.tsx
Mamadou DICKO b0514d6149
fix(i18n): update tests for french and spanish (#878)
* add libraries for traslation purposes

* Add button and service for language selection

* add spanish translation on login page

* add spanish translation on upload page

* Add spanish translations for explore page

* Add translations on user page

* Add translations for config page

* Add spanish translations on chat page

* add translations for brain page

* fix GUI and save on local storage

* fix (i18n) init and types

* fix (i18n): typos

* add translation on new brain modal

* add translations on metadata

* Add translations on home page

* fixes types

* fix(frontend-tests): use get by id instead of text

---------

Co-authored-by: Gustavo Maciel <gustavo_m13@outlook.com>
2023-08-07 14:13:41 +02:00

67 lines
2.0 KiB
TypeScript

/* eslint-disable */
"use client";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import Spinner from "@/lib/components/ui/Spinner";
import { useAxios } from "@/lib/hooks";
import { UserStats } from "@/lib/types/User";
import { useSupabase } from "@/lib/context/SupabaseProvider";
import { redirectToLogin } from "@/lib/router/redirectToLogin";
import { UserStatistics } from "./components/UserStatistics";
const UserPage = (): JSX.Element => {
const [userStats, setUserStats] = useState<UserStats>();
const { session } = useSupabase();
const { axiosInstance } = useAxios();
const { t } = useTranslation(["translation","user"]);
if (session === null) {
redirectToLogin();
}
useEffect(() => {
const fetchUserStats = async () => {
try {
console.log(
`Fetching user stats from ${process.env.NEXT_PUBLIC_BACKEND_URL}/user`
);
const response = await axiosInstance.get<UserStats>(
`${process.env.NEXT_PUBLIC_BACKEND_URL}/user`,
{
headers: {
Authorization: `Bearer ${session.access_token}`,
},
}
);
setUserStats(response.data);
} catch (error) {
console.error("Error fetching user stats", error);
setUserStats(undefined);
}
};
fetchUserStats();
}, [session.access_token]);
return (
<main className="w-full flex flex-col pt-10">
<section className="flex flex-col justify-center items-center flex-1 gap-5 h-full">
<div className="p-5 max-w-3xl w-full min-h-full flex-1 mb-24">
{userStats ? (
<>
<UserStatistics {...userStats} />
</>
) : (
<div className="flex items-center justify-center">
<span>{t("fetching", {ns: "user"})}</span>
<Spinner />
</div>
)}
</div>
</section>
</main>
);
};
export default UserPage;