import React from "react"; import { observer } from "mobx-react"; import { useRouter } from "next/router"; import { Controller, useForm } from "react-hook-form"; import { AlertTriangle } from "lucide-react"; import { Dialog, Transition } from "@headlessui/react"; import type { IWorkspace } from "@plane/types"; // ui import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui"; // constants import { WORKSPACE_DELETED } from "@/constants/event-tracker"; // hooks import { useEventTracker, useWorkspace } from "@/hooks/store"; // types type Props = { isOpen: boolean; data: IWorkspace | null; onClose: () => void; }; const defaultValues = { workspaceName: "", confirmDelete: "", }; export const DeleteWorkspaceModal: React.FC = observer((props) => { const { isOpen, data, onClose } = props; // router const router = useRouter(); // store hooks const { captureWorkspaceEvent } = useEventTracker(); const { deleteWorkspace } = useWorkspace(); // form info const { control, formState: { errors, isSubmitting }, handleSubmit, reset, watch, } = useForm({ defaultValues }); const canDelete = watch("workspaceName") === data?.name && watch("confirmDelete") === "delete my workspace"; const handleClose = () => { const timer = setTimeout(() => { reset(defaultValues); clearTimeout(timer); }, 350); onClose(); }; const onSubmit = async () => { if (!data || !canDelete) return; await deleteWorkspace(data.slug) .then(() => { handleClose(); router.push("/"); captureWorkspaceEvent({ eventName: WORKSPACE_DELETED, payload: { ...data, state: "SUCCESS", element: "Workspace general settings page", }, }); setToast({ type: TOAST_TYPE.SUCCESS, title: "Success!", message: "Workspace deleted successfully.", }); }) .catch(() => { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Something went wrong. Please try again later.", }); captureWorkspaceEvent({ eventName: WORKSPACE_DELETED, payload: { ...data, state: "FAILED", element: "Workspace general settings page", }, }); }); }; return (

Delete Workspace

Are you sure you want to delete workspace{" "} {data?.name}? All of the data related to the workspace will be permanently removed. This action cannot be undone.

Enter the workspace name {data?.name} to continue:

( )} />

To confirm, type delete my workspace{" "} below:

( )} />
); });