2023-06-15 12:52:46 +03:00
|
|
|
/* eslint-disable */
|
2023-06-05 18:58:59 +03:00
|
|
|
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
2023-08-07 15:13:41 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
2023-06-15 12:52:46 +03:00
|
|
|
|
|
|
|
import Spinner from "@/lib/components/ui/Spinner";
|
|
|
|
import { UserStats } from "@/lib/types/User";
|
|
|
|
|
2023-09-13 14:47:12 +03:00
|
|
|
import { USER_DATA_KEY } from "@/lib/api/user/config";
|
|
|
|
import { useUserApi } from "@/lib/api/user/useUserApi";
|
2023-09-26 10:29:30 +03:00
|
|
|
import { DarkModeToggle } from "@/lib/components/NavBar/components/NavItems/components/DarkModeToggle";
|
|
|
|
import { LanguageDropDown } from "@/lib/components/NavBar/components/NavItems/components/LanguageDropDown";
|
2023-06-20 17:17:13 +03:00
|
|
|
import { useSupabase } from "@/lib/context/SupabaseProvider";
|
2023-07-13 19:05:08 +03:00
|
|
|
import { redirectToLogin } from "@/lib/router/redirectToLogin";
|
2023-09-13 14:47:12 +03:00
|
|
|
import { useQuery } from "@tanstack/react-query";
|
2023-06-06 18:32:48 +03:00
|
|
|
import { UserStatistics } from "./components/UserStatistics";
|
2023-06-05 18:58:59 +03:00
|
|
|
|
2023-06-15 12:52:46 +03:00
|
|
|
const UserPage = (): JSX.Element => {
|
2023-06-05 18:58:59 +03:00
|
|
|
const [userStats, setUserStats] = useState<UserStats>();
|
|
|
|
const { session } = useSupabase();
|
2023-09-13 14:47:12 +03:00
|
|
|
const { t } = useTranslation(["translation", "user"]);
|
|
|
|
const { getUser } = useUserApi();
|
2023-07-13 19:05:08 +03:00
|
|
|
|
2023-09-13 14:47:12 +03:00
|
|
|
const { data: userData } = useQuery({
|
|
|
|
queryKey: [USER_DATA_KEY],
|
|
|
|
queryFn: getUser,
|
|
|
|
});
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (userData !== undefined) {
|
|
|
|
setUserStats(userData);
|
|
|
|
}
|
|
|
|
}, [userData]);
|
2023-06-05 18:58:59 +03:00
|
|
|
if (session === null) {
|
2023-07-13 19:05:08 +03:00
|
|
|
redirectToLogin();
|
2023-06-05 18:58:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-06-11 11:44:23 +03:00
|
|
|
<main className="w-full flex flex-col pt-10">
|
2023-06-05 18:58:59 +03:00
|
|
|
<section className="flex flex-col justify-center items-center flex-1 gap-5 h-full">
|
2023-09-26 10:29:30 +03:00
|
|
|
<div className="flex sm:flex-1 sm:justify-end flex-row items-center justify-center sm:flex-row gap-5 sm:gap-2">
|
|
|
|
<LanguageDropDown />
|
|
|
|
<DarkModeToggle />
|
|
|
|
</div>
|
2023-06-06 18:32:48 +03:00
|
|
|
<div className="p-5 max-w-3xl w-full min-h-full flex-1 mb-24">
|
|
|
|
{userStats ? (
|
2023-06-05 18:58:59 +03:00
|
|
|
<>
|
|
|
|
<UserStatistics {...userStats} />
|
|
|
|
</>
|
2023-06-06 18:32:48 +03:00
|
|
|
) : (
|
|
|
|
<div className="flex items-center justify-center">
|
2023-09-13 14:47:12 +03:00
|
|
|
<span>{t("fetching", { ns: "user" })}</span>
|
2023-06-06 18:32:48 +03:00
|
|
|
<Spinner />
|
|
|
|
</div>
|
2023-06-05 18:58:59 +03:00
|
|
|
)}
|
2023-06-06 18:32:48 +03:00
|
|
|
</div>
|
2023-06-05 18:58:59 +03:00
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
);
|
2023-06-15 12:52:46 +03:00
|
|
|
};
|
|
|
|
export default UserPage;
|