2023-06-05 18:58:59 +03:00
|
|
|
"use client";
|
2023-08-07 15:13:41 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
2023-06-15 12:52:46 +03:00
|
|
|
|
2023-09-26 19:26:19 +03:00
|
|
|
import { DarkModeToggle } from "@/app/user/components/DarkModeToggle";
|
|
|
|
import { LanguageDropDown } from "@/app/user/components/LanguageDropDown";
|
2023-06-15 12:52:46 +03:00
|
|
|
import Spinner from "@/lib/components/ui/Spinner";
|
2023-06-20 17:17:13 +03:00
|
|
|
import { useSupabase } from "@/lib/context/SupabaseProvider";
|
2023-09-26 19:26:19 +03:00
|
|
|
import { useUserData } from "@/lib/hooks/useUserData";
|
2023-07-13 19:05:08 +03:00
|
|
|
import { redirectToLogin } from "@/lib/router/redirectToLogin";
|
2023-09-26 19:26:19 +03:00
|
|
|
|
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 { session } = useSupabase();
|
2023-09-13 14:47:12 +03:00
|
|
|
const { t } = useTranslation(["translation", "user"]);
|
2023-07-13 19:05:08 +03:00
|
|
|
|
2023-09-26 19:26:19 +03:00
|
|
|
const { userData: userStats } = useUserData();
|
2023-09-13 14:47:12 +03:00
|
|
|
|
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;
|