2023-06-05 18:58:59 +03:00
|
|
|
"use client";
|
2023-06-15 12:52:46 +03:00
|
|
|
|
2024-02-04 04:45:05 +03:00
|
|
|
import { useState } from "react";
|
2024-02-07 03:05:07 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
2024-02-04 04:45:05 +03:00
|
|
|
|
2024-02-07 03:05:07 +03:00
|
|
|
import PageHeader from "@/lib/components/PageHeader/PageHeader";
|
|
|
|
import { Modal } from "@/lib/components/ui/Modal";
|
|
|
|
import QuivrButton from "@/lib/components/ui/QuivrButton/QuivrButton";
|
|
|
|
import { Tabs } from "@/lib/components/ui/Tabs/Tabs";
|
2023-06-20 17:17:13 +03:00
|
|
|
import { useSupabase } from "@/lib/context/SupabaseProvider";
|
2024-02-04 04:45:05 +03:00
|
|
|
import { useUserData } from "@/lib/hooks/useUserData";
|
2023-07-13 19:05:08 +03:00
|
|
|
import { redirectToLogin } from "@/lib/router/redirectToLogin";
|
2024-02-07 03:05:07 +03:00
|
|
|
import { ButtonType } from "@/lib/types/QuivrButton";
|
|
|
|
import { Tab } from "@/lib/types/Tab";
|
2023-09-26 19:26:19 +03:00
|
|
|
|
2024-02-04 04:45:05 +03:00
|
|
|
import { BrainsUsage } from "./components/BrainsUsage/BrainsUsage";
|
|
|
|
import { Plan } from "./components/Plan/Plan";
|
|
|
|
import { Settings } from "./components/Settings/Settings";
|
|
|
|
import styles from "./page.module.scss";
|
2023-06-05 18:58:59 +03:00
|
|
|
|
2024-02-07 03:05:07 +03:00
|
|
|
import { useLogoutModal } from "../../lib/hooks/useLogoutModal";
|
|
|
|
|
2023-06-15 12:52:46 +03:00
|
|
|
const UserPage = (): JSX.Element => {
|
2024-02-07 03:05:07 +03:00
|
|
|
const [selectedTab, setSelectedTab] = useState("Settings");
|
2023-06-05 18:58:59 +03:00
|
|
|
const { session } = useSupabase();
|
2024-02-04 04:45:05 +03:00
|
|
|
const { userData } = useUserData();
|
2024-02-07 03:05:07 +03:00
|
|
|
const { t } = useTranslation(["translation", "logout"]);
|
|
|
|
const {
|
|
|
|
handleLogout,
|
|
|
|
isLoggingOut,
|
|
|
|
isLogoutModalOpened,
|
|
|
|
setIsLogoutModalOpened,
|
|
|
|
} = useLogoutModal();
|
2024-02-04 04:45:05 +03:00
|
|
|
|
2024-02-07 03:05:07 +03:00
|
|
|
const button: ButtonType = {
|
|
|
|
label: "Logout",
|
|
|
|
color: "dangerous",
|
|
|
|
onClick: () => {
|
|
|
|
setIsLogoutModalOpened(true);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const userTabs: Tab[] = [
|
2024-02-04 04:45:05 +03:00
|
|
|
{
|
2024-02-07 03:05:07 +03:00
|
|
|
label: "Settings",
|
|
|
|
isSelected: selectedTab === "Settings",
|
|
|
|
onClick: () => setSelectedTab("Settings"),
|
2024-02-07 08:59:59 +03:00
|
|
|
iconName: "settings",
|
2024-02-04 04:45:05 +03:00
|
|
|
},
|
|
|
|
{
|
2024-02-07 03:05:07 +03:00
|
|
|
label: "Brains Usage",
|
|
|
|
isSelected: selectedTab === "Brains Usage",
|
|
|
|
onClick: () => setSelectedTab("Brains Usage"),
|
2024-02-07 08:59:59 +03:00
|
|
|
iconName: "graph",
|
2024-02-04 04:45:05 +03:00
|
|
|
},
|
|
|
|
{
|
2024-02-07 03:05:07 +03:00
|
|
|
label: "Plan",
|
|
|
|
isSelected: selectedTab === "Plan",
|
|
|
|
onClick: () => setSelectedTab("Plan"),
|
2024-02-07 08:59:59 +03:00
|
|
|
iconName: "star",
|
2024-02-04 04:45:05 +03:00
|
|
|
},
|
2024-02-07 03:05:07 +03:00
|
|
|
];
|
2023-07-13 19:05:08 +03:00
|
|
|
|
2024-02-04 04:45:05 +03:00
|
|
|
if (!session || !userData) {
|
2023-07-13 19:05:08 +03:00
|
|
|
redirectToLogin();
|
2023-06-05 18:58:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-10-26 19:23:36 +03:00
|
|
|
<>
|
2024-02-07 03:05:07 +03:00
|
|
|
<div className={styles.page_header}>
|
|
|
|
<PageHeader iconName="user" label="Profile" buttons={[button]} />
|
|
|
|
</div>
|
|
|
|
<div className={styles.user_page_container}>
|
|
|
|
<Tabs tabList={userTabs} />
|
2024-02-04 04:45:05 +03:00
|
|
|
<div className={styles.content_wrapper}>
|
2024-02-07 03:05:07 +03:00
|
|
|
{userTabs[0].isSelected && <Settings email={userData.email} />}
|
|
|
|
{userTabs[1].isSelected && <BrainsUsage />}
|
|
|
|
{userTabs[2].isSelected && <Plan />}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Modal
|
|
|
|
isOpen={isLogoutModalOpened}
|
|
|
|
setOpen={setIsLogoutModalOpened}
|
|
|
|
CloseTrigger={<div />}
|
|
|
|
>
|
|
|
|
<div className="text-center flex flex-col items-center gap-5">
|
|
|
|
<h2 className="text-lg font-medium mb-5">
|
|
|
|
{t("areYouSure", { ns: "logout" })}
|
|
|
|
</h2>
|
|
|
|
<div className="flex gap-5 items-center justify-center">
|
|
|
|
<QuivrButton
|
|
|
|
onClick={() => setIsLogoutModalOpened(false)}
|
|
|
|
color="primary"
|
|
|
|
label={t("cancel", { ns: "logout" })}
|
|
|
|
></QuivrButton>
|
|
|
|
<QuivrButton
|
|
|
|
isLoading={isLoggingOut}
|
|
|
|
color="dangerous"
|
|
|
|
onClick={() => void handleLogout()}
|
|
|
|
label={t("logoutButton")}
|
|
|
|
></QuivrButton>
|
|
|
|
</div>
|
2024-02-04 04:45:05 +03:00
|
|
|
</div>
|
2024-02-07 03:05:07 +03:00
|
|
|
</Modal>
|
2023-10-26 19:23:36 +03:00
|
|
|
</>
|
2023-06-05 18:58:59 +03:00
|
|
|
);
|
2023-06-15 12:52:46 +03:00
|
|
|
};
|
2023-10-05 18:50:02 +03:00
|
|
|
|
2023-06-15 12:52:46 +03:00
|
|
|
export default UserPage;
|