"use client"; import { useState } from "react"; import { useTranslation } from "react-i18next"; 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"; import { useSupabase } from "@/lib/context/SupabaseProvider"; import { useUserData } from "@/lib/hooks/useUserData"; import { redirectToLogin } from "@/lib/router/redirectToLogin"; import { ButtonType } from "@/lib/types/QuivrButton"; import { Tab } from "@/lib/types/Tab"; import { BrainsUsage } from "./components/BrainsUsage/BrainsUsage"; import { Plan } from "./components/Plan/Plan"; import { Settings } from "./components/Settings/Settings"; import styles from "./page.module.scss"; import { useLogoutModal } from "../../lib/hooks/useLogoutModal"; const UserPage = (): JSX.Element => { const [selectedTab, setSelectedTab] = useState("Settings"); const { session } = useSupabase(); const { userData } = useUserData(); const { t } = useTranslation(["translation", "logout"]); const { handleLogout, isLoggingOut, isLogoutModalOpened, setIsLogoutModalOpened, } = useLogoutModal(); const button: ButtonType = { label: "Logout", color: "dangerous", onClick: () => { setIsLogoutModalOpened(true); }, iconName: "logout", }; const userTabs: Tab[] = [ { label: "Settings", isSelected: selectedTab === "Settings", onClick: () => setSelectedTab("Settings"), iconName: "settings", }, { label: "Brains Usage", isSelected: selectedTab === "Brains Usage", onClick: () => setSelectedTab("Brains Usage"), iconName: "graph", }, { label: "Plan", isSelected: selectedTab === "Plan", onClick: () => setSelectedTab("Plan"), iconName: "star", }, ]; if (!session || !userData) { redirectToLogin(); } return ( <>
{userTabs[0].isSelected && } {userTabs[1].isSelected && } {userTabs[2].isSelected && }
} >

{t("areYouSure", { ns: "logout" })}

setIsLogoutModalOpened(false)} color="primary" label={t("cancel", { ns: "logout" })} iconName="close" > void handleLogout()} label={t("logoutButton")} iconName="logout" >
); }; export default UserPage;