2023-07-24 15:17:21 +03:00
|
|
|
"use client";
|
|
|
|
|
2024-02-29 03:42:14 +03:00
|
|
|
import { useEffect } from "react";
|
2023-12-18 20:02:34 +03:00
|
|
|
|
2024-07-22 18:42:45 +03:00
|
|
|
import { PageHeader } from "@/lib/components/PageHeader/PageHeader";
|
2024-02-29 03:42:14 +03:00
|
|
|
import { UploadDocumentModal } from "@/lib/components/UploadDocumentModal/UploadDocumentModal";
|
|
|
|
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
|
|
|
|
import { useKnowledgeToFeedContext } from "@/lib/context/KnowledgeToFeedProvider/hooks/useKnowledgeToFeedContext";
|
2024-08-28 03:30:48 +03:00
|
|
|
import { useSearchModalContext } from "@/lib/context/SearchModalProvider/hooks/useSearchModalContext";
|
2024-02-29 03:42:14 +03:00
|
|
|
import { ButtonType } from "@/lib/types/QuivrButton";
|
2023-12-18 20:02:34 +03:00
|
|
|
|
2024-02-29 03:42:14 +03:00
|
|
|
import { BrainManagementTabs } from "./BrainManagementTabs/BrainManagementTabs";
|
|
|
|
import { DeleteOrUnsubscribeConfirmationModal } from "./BrainManagementTabs/components/DeleteOrUnsubscribeModal/DeleteOrUnsubscribeConfirmationModal";
|
|
|
|
import { useBrainManagementTabs } from "./BrainManagementTabs/hooks/useBrainManagementTabs";
|
|
|
|
import { getBrainPermissions } from "./BrainManagementTabs/utils/getBrainPermissions";
|
2023-12-18 20:02:34 +03:00
|
|
|
import { useBrainManagement } from "./hooks/useBrainManagement";
|
2024-02-29 03:42:14 +03:00
|
|
|
import styles from "./page.module.scss";
|
2023-07-25 10:54:34 +03:00
|
|
|
|
2023-07-24 15:17:21 +03:00
|
|
|
const BrainsManagement = (): JSX.Element => {
|
2023-12-18 20:02:34 +03:00
|
|
|
const { brain } = useBrainManagement();
|
2024-08-28 03:30:48 +03:00
|
|
|
const { setIsVisible } = useSearchModalContext();
|
2024-02-29 03:42:14 +03:00
|
|
|
const {
|
|
|
|
handleUnsubscribeOrDeleteBrain,
|
|
|
|
isDeleteOrUnsubscribeModalOpened,
|
|
|
|
setIsDeleteOrUnsubscribeModalOpened,
|
|
|
|
isDeleteOrUnsubscribeRequestPending,
|
|
|
|
} = useBrainManagementTabs(brain?.id);
|
|
|
|
const { allBrains } = useBrainContext();
|
|
|
|
const { isOwnedByCurrentUser } = getBrainPermissions({
|
|
|
|
brainId: brain?.id,
|
|
|
|
userAccessibleBrains: allBrains,
|
|
|
|
});
|
|
|
|
const { setShouldDisplayFeedCard } = useKnowledgeToFeedContext();
|
|
|
|
const { setCurrentBrainId } = useBrainContext();
|
|
|
|
|
|
|
|
const buttons: ButtonType[] = [
|
2024-08-28 03:30:48 +03:00
|
|
|
{
|
|
|
|
label: "Talk to Brain",
|
|
|
|
color: "primary",
|
|
|
|
onClick: () => {
|
|
|
|
if (brain) {
|
|
|
|
setIsVisible(true);
|
|
|
|
setTimeout(() => setCurrentBrainId(brain.id));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
iconName: "chat",
|
|
|
|
},
|
2024-02-29 03:42:14 +03:00
|
|
|
{
|
|
|
|
label: "Add knowledge",
|
|
|
|
color: "primary",
|
|
|
|
onClick: () => {
|
|
|
|
setShouldDisplayFeedCard(true);
|
|
|
|
},
|
|
|
|
iconName: "uploadFile",
|
|
|
|
hidden: !isOwnedByCurrentUser || !brain?.max_files,
|
|
|
|
},
|
|
|
|
{
|
2024-03-21 21:51:10 +03:00
|
|
|
label: isOwnedByCurrentUser ? "Delete Brain" : "Unsubscribe from Brain",
|
2024-02-29 03:42:14 +03:00
|
|
|
color: "dangerous",
|
|
|
|
onClick: () => {
|
|
|
|
setIsDeleteOrUnsubscribeModalOpened(true);
|
|
|
|
},
|
|
|
|
iconName: "delete",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (brain) {
|
|
|
|
setCurrentBrainId(brain.id);
|
|
|
|
}
|
|
|
|
}, [brain]);
|
|
|
|
|
|
|
|
if (!brain) {
|
|
|
|
return <></>;
|
|
|
|
}
|
2023-12-18 20:02:34 +03:00
|
|
|
|
|
|
|
return (
|
2024-02-29 03:42:14 +03:00
|
|
|
<>
|
|
|
|
<div className={styles.brain_management_wrapper}>
|
2024-08-21 18:23:59 +03:00
|
|
|
<PageHeader
|
|
|
|
iconName="brain"
|
|
|
|
label={brain.name}
|
|
|
|
buttons={buttons}
|
|
|
|
snippetEmoji={brain.snippet_emoji}
|
|
|
|
snippetColor={brain.snippet_color}
|
|
|
|
/>
|
2024-02-29 03:42:14 +03:00
|
|
|
<div className={styles.content_wrapper}>
|
|
|
|
<BrainManagementTabs />
|
|
|
|
</div>
|
2023-12-18 20:02:34 +03:00
|
|
|
</div>
|
2024-02-29 03:42:14 +03:00
|
|
|
<UploadDocumentModal />
|
|
|
|
<DeleteOrUnsubscribeConfirmationModal
|
|
|
|
isOpen={isDeleteOrUnsubscribeModalOpened}
|
|
|
|
setOpen={setIsDeleteOrUnsubscribeModalOpened}
|
|
|
|
onConfirm={() => void handleUnsubscribeOrDeleteBrain()}
|
|
|
|
isOwnedByCurrentUser={isOwnedByCurrentUser}
|
|
|
|
isDeleteOrUnsubscribeRequestPending={
|
|
|
|
isDeleteOrUnsubscribeRequestPending
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</>
|
2023-12-18 20:02:34 +03:00
|
|
|
);
|
2023-07-24 15:17:21 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export default BrainsManagement;
|