2023-07-25 11:13:00 +03:00
|
|
|
import { UUID } from "crypto";
|
2023-08-08 19:18:05 +03:00
|
|
|
import { useParams, useRouter } from "next/navigation";
|
2023-07-25 10:54:34 +03:00
|
|
|
import { useState } from "react";
|
|
|
|
|
2023-08-08 19:18:05 +03:00
|
|
|
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
|
|
|
|
|
2023-07-25 10:54:34 +03:00
|
|
|
import { BrainManagementTab } from "../types";
|
2023-08-31 17:02:32 +03:00
|
|
|
import { getTargetedTab } from "../utils/getTargetedTab";
|
2023-07-25 10:54:34 +03:00
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
|
export const useBrainManagementTabs = () => {
|
2023-08-31 17:02:32 +03:00
|
|
|
const [selectedTab, setSelectedTab] = useState<BrainManagementTab>(
|
|
|
|
getTargetedTab() ?? "settings"
|
|
|
|
);
|
|
|
|
|
2023-08-08 19:18:05 +03:00
|
|
|
const { deleteBrain, setCurrentBrainId } = useBrainContext();
|
|
|
|
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
|
|
|
const router = useRouter();
|
2023-07-25 10:54:34 +03:00
|
|
|
|
2023-07-25 11:13:00 +03:00
|
|
|
const params = useParams();
|
|
|
|
|
|
|
|
const brainId = params?.brainId as UUID | undefined;
|
|
|
|
|
2023-08-08 19:18:05 +03:00
|
|
|
const handleDeleteBrain = () => {
|
|
|
|
if (brainId === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
void deleteBrain(brainId);
|
|
|
|
setCurrentBrainId(null);
|
|
|
|
router.push("/brains-management");
|
|
|
|
setIsDeleteModalOpen(false);
|
|
|
|
};
|
|
|
|
|
2023-07-25 10:54:34 +03:00
|
|
|
return {
|
|
|
|
selectedTab,
|
|
|
|
setSelectedTab,
|
2023-07-25 11:13:00 +03:00
|
|
|
brainId,
|
2023-08-08 19:18:05 +03:00
|
|
|
handleDeleteBrain,
|
|
|
|
isDeleteModalOpen,
|
|
|
|
setIsDeleteModalOpen,
|
2023-07-25 10:54:34 +03:00
|
|
|
};
|
|
|
|
};
|