mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-21 02:11:35 +03:00
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { UUID } from "crypto";
|
|
import { useParams, useRouter } from "next/navigation";
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
|
|
|
|
import { BrainManagementTab } from "../types";
|
|
import { getTargetedTab } from "../utils/getTargetedTab";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
export const useBrainManagementTabs = () => {
|
|
const [selectedTab, setSelectedTab] =
|
|
useState<BrainManagementTab>("settings");
|
|
|
|
useEffect(() => {
|
|
const targetedTab = getTargetedTab();
|
|
if (targetedTab !== undefined) {
|
|
setSelectedTab(targetedTab);
|
|
}
|
|
}, []);
|
|
|
|
const { deleteBrain, setCurrentBrainId } = useBrainContext();
|
|
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
|
const router = useRouter();
|
|
|
|
const params = useParams();
|
|
|
|
const brainId = params?.brainId as UUID | undefined;
|
|
|
|
const handleDeleteBrain = () => {
|
|
if (brainId === undefined) {
|
|
return;
|
|
}
|
|
void deleteBrain(brainId);
|
|
setCurrentBrainId(null);
|
|
router.push("/brains-management");
|
|
setIsDeleteModalOpen(false);
|
|
};
|
|
|
|
return {
|
|
selectedTab,
|
|
setSelectedTab,
|
|
brainId,
|
|
handleDeleteBrain,
|
|
isDeleteModalOpen,
|
|
setIsDeleteModalOpen,
|
|
};
|
|
};
|