quivr/frontend/app/brains-management/[brainId]/components/BrainManagementTabs/hooks/useBrainManagementTabs.ts
Stepan Lebedev 71e142ba3c
feat: deleting brains on brain manager page (#893)
* fix: new libraries for translation

* feat(deleting-brains-on-brain-management-page): adding a delete brain button and a confirmation modal on a management page

* feat(deleting-brains-on-brain-management-page): adding tests for confirmation Modal

* feat(deleting-brains-on-brain-management-page): Adding translation to the delete button and modal
2023-08-08 17:18:05 +01:00

40 lines
1.1 KiB
TypeScript

import { UUID } from "crypto";
import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";
import { BrainManagementTab } from "../types";
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useBrainManagementTabs = () => {
const [selectedTab, setSelectedTab] =
useState<BrainManagementTab>("settings");
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,
};
};