import { Button, Icon, AlertDialog, AlertDialogBody, AlertDialogFooter, AlertDialogHeader, AlertDialogContent, AlertDialogOverlay, useDisclosure, Text, } from "@chakra-ui/react"; import { useRouter } from "next/router"; import { useRef } from "react"; import { BsTrash } from "react-icons/bs"; import { api } from "~/utils/api"; import { useExperiment, useHandledAsyncCallback } from "~/utils/hooks"; export const DeleteButton = () => { const experiment = useExperiment(); const mutation = api.experiments.delete.useMutation(); const utils = api.useContext(); const router = useRouter(); const { isOpen, onOpen, onClose } = useDisclosure(); const cancelRef = useRef(null); const [onDeleteConfirm] = useHandledAsyncCallback(async () => { if (!experiment.data?.id) return; await mutation.mutateAsync({ id: experiment.data.id }); await utils.experiments.list.invalidate(); await router.push({ pathname: "/experiments" }); onClose(); }, [mutation, experiment.data?.id, router]); return ( <> Delete Experiment If you delete this experiment all the associated prompts and scenarios will be deleted as well. Are you sure? ); };