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";
|
|
|
|
|
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";
|
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 { UserMenuCard } from "./components/UserMenuCard/UserMenuCard";
|
|
|
|
import { UserMenuCardProps } from "./components/types/types";
|
|
|
|
import styles from "./page.module.scss";
|
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();
|
2024-02-04 04:45:05 +03:00
|
|
|
const { userData } = useUserData();
|
|
|
|
|
|
|
|
const [userMenuCards, setUserMenuCards] = useState<UserMenuCardProps[]>([
|
|
|
|
{
|
|
|
|
title: "Settings",
|
|
|
|
subtitle: "Change your settings",
|
|
|
|
iconName: "settings",
|
|
|
|
selected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Brain Usage",
|
|
|
|
subtitle: "View your brain usage",
|
|
|
|
iconName: "graph",
|
|
|
|
selected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Plan",
|
|
|
|
subtitle: "Manage your plan",
|
|
|
|
iconName: "unlock",
|
|
|
|
selected: false,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
const handleCardClick = (index: number) => {
|
|
|
|
setUserMenuCards(
|
|
|
|
userMenuCards.map((card, i) => ({
|
|
|
|
...card,
|
|
|
|
selected: i === index,
|
|
|
|
}))
|
|
|
|
);
|
|
|
|
};
|
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-04 04:45:05 +03:00
|
|
|
<main className={styles.user_page_container}>
|
|
|
|
<div className={styles.left_menu_wrapper}>
|
|
|
|
{userMenuCards.map((card, index) => (
|
|
|
|
<UserMenuCard
|
|
|
|
key={index}
|
|
|
|
title={card.title}
|
|
|
|
subtitle={card.subtitle}
|
|
|
|
iconName={card.iconName}
|
|
|
|
selected={card.selected}
|
|
|
|
onClick={() => handleCardClick(index)}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<div className={styles.content_wrapper}>
|
|
|
|
{userMenuCards[0].selected && <Settings email={userData.email} />}
|
|
|
|
{userMenuCards[1].selected && <BrainsUsage />}
|
|
|
|
{userMenuCards[2].selected && <Plan />}
|
|
|
|
</div>
|
2023-10-26 19:23:36 +03:00
|
|
|
</main>
|
|
|
|
</>
|
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;
|