"use client"; import { useState } from "react"; import { useSupabase } from "@/lib/context/SupabaseProvider"; import { useUserData } from "@/lib/hooks/useUserData"; import { redirectToLogin } from "@/lib/router/redirectToLogin"; 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"; const UserPage = (): JSX.Element => { const { session } = useSupabase(); const { userData } = useUserData(); const [userMenuCards, setUserMenuCards] = useState([ { 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, })) ); }; if (!session || !userData) { redirectToLogin(); } return ( <>
{userMenuCards.map((card, index) => ( handleCardClick(index)} /> ))}
{userMenuCards[0].selected && } {userMenuCards[1].selected && } {userMenuCards[2].selected && }
); }; export default UserPage;