2023-09-22 12:44:09 +03:00
|
|
|
/* eslint-disable max-lines */
|
2023-07-25 10:54:34 +03:00
|
|
|
import { Content, List, Root } from "@radix-ui/react-tabs";
|
2023-08-07 15:13:41 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
2023-07-25 10:54:34 +03:00
|
|
|
|
2023-08-08 19:18:05 +03:00
|
|
|
import Button from "@/lib/components/ui/Button";
|
|
|
|
|
2023-10-27 13:52:39 +03:00
|
|
|
import {
|
|
|
|
BrainTabTrigger,
|
|
|
|
KnowledgeTab,
|
|
|
|
PeopleTab,
|
|
|
|
SettingsTab,
|
|
|
|
} from "./components";
|
2023-09-25 15:22:59 +03:00
|
|
|
import { DeleteOrUnsubscribeConfirmationModal } from "./components/Modals/DeleteOrUnsubscribeConfirmationModal";
|
2023-07-25 10:54:34 +03:00
|
|
|
import { useBrainManagementTabs } from "./hooks/useBrainManagementTabs";
|
|
|
|
|
|
|
|
export const BrainManagementTabs = (): JSX.Element => {
|
2023-09-25 15:22:59 +03:00
|
|
|
const { t } = useTranslation([
|
|
|
|
"translation",
|
|
|
|
"config",
|
|
|
|
"delete_or_unsubscribe_from_brain",
|
|
|
|
]);
|
2023-08-08 19:18:05 +03:00
|
|
|
const {
|
|
|
|
selectedTab,
|
|
|
|
setSelectedTab,
|
|
|
|
brainId,
|
2023-09-25 15:22:59 +03:00
|
|
|
handleUnsubscribeOrDeleteBrain,
|
|
|
|
isDeleteOrUnsubscribeModalOpened,
|
|
|
|
setIsDeleteOrUnsubscribeModalOpened,
|
|
|
|
hasEditRights,
|
2023-11-16 21:57:02 +03:00
|
|
|
isPublicBrain,
|
2023-09-25 15:22:59 +03:00
|
|
|
isOwnedByCurrentUser,
|
|
|
|
isDeleteOrUnsubscribeRequestPending,
|
2023-08-08 19:18:05 +03:00
|
|
|
} = useBrainManagementTabs();
|
2023-09-20 17:24:56 +03:00
|
|
|
|
2023-07-25 11:13:00 +03:00
|
|
|
if (brainId === undefined) {
|
|
|
|
return <div />;
|
|
|
|
}
|
2023-07-25 10:54:34 +03:00
|
|
|
|
|
|
|
return (
|
2023-10-03 15:56:31 +03:00
|
|
|
<div className="flex justify-center w-full">
|
|
|
|
<Root
|
2023-11-03 12:01:05 +03:00
|
|
|
className="flex flex-col w-full h-full overflow-scroll bg-white dark:bg-black p-4 md:p-10 max-w-5xl"
|
2023-10-03 15:56:31 +03:00
|
|
|
value={selectedTab}
|
2023-08-08 19:18:05 +03:00
|
|
|
>
|
2023-10-03 15:56:31 +03:00
|
|
|
<List
|
|
|
|
className="flex flex-col md:flex-row justify-between space-y-2 md:space-y-0 mb-4"
|
|
|
|
aria-label={t("subtitle", { ns: "config" })}
|
|
|
|
>
|
|
|
|
<BrainTabTrigger
|
|
|
|
selected={selectedTab === "settings"}
|
|
|
|
label={t("settings", { ns: "config" })}
|
|
|
|
value="settings"
|
|
|
|
onChange={setSelectedTab}
|
|
|
|
/>
|
2023-11-16 21:57:02 +03:00
|
|
|
{(!isPublicBrain || hasEditRights) && (
|
2023-10-03 15:56:31 +03:00
|
|
|
<>
|
|
|
|
<BrainTabTrigger
|
|
|
|
selected={selectedTab === "people"}
|
|
|
|
label={t("people", { ns: "config" })}
|
|
|
|
value="people"
|
|
|
|
onChange={setSelectedTab}
|
|
|
|
/>
|
|
|
|
<BrainTabTrigger
|
|
|
|
selected={selectedTab === "knowledge"}
|
|
|
|
label={t("knowledge", { ns: "config" })}
|
|
|
|
value="knowledge"
|
|
|
|
onChange={setSelectedTab}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</List>
|
2023-07-25 11:13:00 +03:00
|
|
|
|
2023-10-03 15:56:31 +03:00
|
|
|
<div className="flex-1 md:pt-0 pb-0">
|
|
|
|
<Content value="settings">
|
|
|
|
<SettingsTab brainId={brainId} />
|
|
|
|
</Content>
|
|
|
|
<Content value="people">
|
2023-11-16 21:57:02 +03:00
|
|
|
<PeopleTab brainId={brainId} hasEditRights={hasEditRights} />
|
2023-10-03 15:56:31 +03:00
|
|
|
</Content>
|
|
|
|
<Content value="knowledge">
|
2023-11-16 21:57:02 +03:00
|
|
|
<KnowledgeTab brainId={brainId} hasEditRights={hasEditRights} />
|
2023-10-03 15:56:31 +03:00
|
|
|
</Content>
|
|
|
|
</div>
|
2023-09-15 02:09:26 +03:00
|
|
|
|
2023-10-03 15:56:31 +03:00
|
|
|
<div className="flex justify-center">
|
|
|
|
{isOwnedByCurrentUser ? (
|
|
|
|
<Button
|
|
|
|
className="px-8 md:px-20 py-2 bg-red-500 text-white rounded-md"
|
|
|
|
onClick={() => setIsDeleteOrUnsubscribeModalOpened(true)}
|
|
|
|
>
|
|
|
|
{t("deleteButton", { ns: "delete_or_unsubscribe_from_brain" })}
|
|
|
|
</Button>
|
|
|
|
) : (
|
|
|
|
<Button
|
|
|
|
className="px-8 md:px-20 py-2 bg-red-500 text-white rounded-md"
|
|
|
|
onClick={() => setIsDeleteOrUnsubscribeModalOpened(true)}
|
|
|
|
>
|
|
|
|
{t("unsubscribeButton", {
|
|
|
|
ns: "delete_or_unsubscribe_from_brain",
|
|
|
|
})}
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-09-15 02:09:26 +03:00
|
|
|
|
2023-10-03 15:56:31 +03:00
|
|
|
<DeleteOrUnsubscribeConfirmationModal
|
|
|
|
isOpen={isDeleteOrUnsubscribeModalOpened}
|
|
|
|
setOpen={setIsDeleteOrUnsubscribeModalOpened}
|
|
|
|
onConfirm={() => void handleUnsubscribeOrDeleteBrain()}
|
|
|
|
isOwnedByCurrentUser={isOwnedByCurrentUser}
|
|
|
|
isDeleteOrUnsubscribeRequestPending={
|
|
|
|
isDeleteOrUnsubscribeRequestPending
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Root>
|
|
|
|
</div>
|
2023-07-25 10:54:34 +03:00
|
|
|
);
|
|
|
|
};
|