2024-02-07 03:05:07 +03:00
|
|
|
"use client";
|
|
|
|
|
2024-07-11 16:37:24 +03:00
|
|
|
import { useEffect, useState } from "react";
|
2024-02-07 03:05:07 +03:00
|
|
|
|
|
|
|
import { AddBrainModal } from "@/lib/components/AddBrainModal";
|
2024-02-15 03:37:33 +03:00
|
|
|
import { useBrainCreationContext } from "@/lib/components/AddBrainModal/brainCreation-provider";
|
2024-02-07 03:05:07 +03:00
|
|
|
import PageHeader from "@/lib/components/PageHeader/PageHeader";
|
|
|
|
import { UploadDocumentModal } from "@/lib/components/UploadDocumentModal/UploadDocumentModal";
|
|
|
|
import { Tabs } from "@/lib/components/ui/Tabs/Tabs";
|
2024-07-11 16:37:24 +03:00
|
|
|
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
|
2024-02-07 03:05:07 +03:00
|
|
|
import { useKnowledgeToFeedContext } from "@/lib/context/KnowledgeToFeedProvider/hooks/useKnowledgeToFeedContext";
|
2024-07-11 16:37:24 +03:00
|
|
|
import { useUserData } from "@/lib/hooks/useUserData";
|
2024-02-07 03:05:07 +03:00
|
|
|
import { ButtonType } from "@/lib/types/QuivrButton";
|
|
|
|
import { Tab } from "@/lib/types/Tab";
|
|
|
|
|
2024-04-10 12:20:21 +03:00
|
|
|
import { Analytics } from "./BrainsTabs/components/Analytics/Analytics";
|
2024-03-04 22:35:34 +03:00
|
|
|
import { ManageBrains } from "./BrainsTabs/components/ManageBrains/ManageBrains";
|
2024-02-07 03:05:07 +03:00
|
|
|
import styles from "./page.module.scss";
|
|
|
|
|
|
|
|
const Studio = (): JSX.Element => {
|
|
|
|
const [selectedTab, setSelectedTab] = useState("Manage my brains");
|
|
|
|
const { setShouldDisplayFeedCard } = useKnowledgeToFeedContext();
|
|
|
|
const { setIsBrainCreationModalOpened } = useBrainCreationContext();
|
2024-07-11 16:37:24 +03:00
|
|
|
const { allBrains } = useBrainContext();
|
|
|
|
const { userData } = useUserData();
|
2024-02-07 03:05:07 +03:00
|
|
|
|
|
|
|
const studioTabs: Tab[] = [
|
|
|
|
{
|
|
|
|
label: "Manage my brains",
|
|
|
|
isSelected: selectedTab === "Manage my brains",
|
|
|
|
onClick: () => setSelectedTab("Manage my brains"),
|
2024-02-07 08:59:59 +03:00
|
|
|
iconName: "edit",
|
2024-02-07 03:05:07 +03:00
|
|
|
},
|
|
|
|
{
|
2024-04-10 12:20:21 +03:00
|
|
|
label: "Analytics",
|
2024-02-07 03:05:07 +03:00
|
|
|
isSelected: selectedTab === "Analytics",
|
|
|
|
onClick: () => setSelectedTab("Analytics"),
|
2024-02-07 08:59:59 +03:00
|
|
|
iconName: "graph",
|
2024-02-07 03:05:07 +03:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2024-07-11 16:37:24 +03:00
|
|
|
const [buttons, setButtons] = useState<ButtonType[]>([
|
2024-02-07 03:05:07 +03:00
|
|
|
{
|
|
|
|
label: "Create brain",
|
|
|
|
color: "primary",
|
|
|
|
onClick: () => {
|
|
|
|
setIsBrainCreationModalOpened(true);
|
|
|
|
},
|
2024-02-07 10:34:50 +03:00
|
|
|
iconName: "brain",
|
2024-07-11 16:37:24 +03:00
|
|
|
tooltip:
|
|
|
|
"You have reached the maximum number of brains allowed. Please upgrade your plan or delete some brains to create a new one.",
|
2024-02-07 03:05:07 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Add knowledge",
|
|
|
|
color: "primary",
|
|
|
|
onClick: () => {
|
|
|
|
setShouldDisplayFeedCard(true);
|
|
|
|
},
|
2024-02-11 03:17:05 +03:00
|
|
|
iconName: "uploadFile",
|
2024-02-07 03:05:07 +03:00
|
|
|
},
|
2024-07-11 16:37:24 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (userData) {
|
|
|
|
setButtons((prevButtons) => {
|
|
|
|
return prevButtons.map((button) => {
|
|
|
|
if (button.label === "Create brain") {
|
|
|
|
return {
|
|
|
|
...button,
|
|
|
|
disabled: userData.max_brains <= allBrains.length,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return button;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [userData?.max_brains, allBrains.length]);
|
2024-02-07 03:05:07 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.page_wrapper}>
|
|
|
|
<div className={styles.page_header}>
|
2024-03-07 22:18:32 +03:00
|
|
|
<PageHeader
|
|
|
|
iconName="brainCircuit"
|
|
|
|
label="Brain Studio"
|
|
|
|
buttons={buttons}
|
|
|
|
/>
|
2024-02-07 03:05:07 +03:00
|
|
|
</div>
|
|
|
|
<div className={styles.content_wrapper}>
|
|
|
|
<Tabs tabList={studioTabs} />
|
|
|
|
{selectedTab === "Manage my brains" && <ManageBrains />}
|
2024-04-10 12:20:21 +03:00
|
|
|
{selectedTab === "Analytics" && <Analytics />}
|
2024-02-07 03:05:07 +03:00
|
|
|
</div>
|
|
|
|
<UploadDocumentModal />
|
|
|
|
<AddBrainModal />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Studio;
|