import { Button, AlertDialog, AlertDialogBody, AlertDialogFooter, AlertDialogHeader, AlertDialogContent, AlertDialogOverlay, Input, Text, VStack, Box, Spinner, } from "@chakra-ui/react"; import { useRouter } from "next/router"; import { useRef, useState } from "react"; import { api } from "~/utils/api"; import { useHandledAsyncCallback, useSelectedProject } from "~/utils/hooks"; export const DeleteProjectDialog = ({ isOpen, onClose, }: { isOpen: boolean; onClose: () => void; }) => { const selectedProject = useSelectedProject(); const deleteMutation = api.projects.delete.useMutation(); const utils = api.useContext(); const router = useRouter(); const cancelRef = useRef(null); const [onDeleteConfirm, isDeleting] = useHandledAsyncCallback(async () => { if (!selectedProject.data?.id) return; await deleteMutation.mutateAsync({ id: selectedProject.data.id }); await utils.projects.list.invalidate(); await router.push({ pathname: "/experiments" }); onClose(); }, [deleteMutation, selectedProject, router]); const [nameToDelete, setNameToDelete] = useState(""); return ( Delete Project If you delete this project all the associated data and experiments will be deleted as well. If you are sure that you want to delete this project, please type the name of the project below. {selectedProject.data?.name} setNameToDelete(e.target.value)} /> ); };