import { useRouter } from "next/navigation"; import { useState } from "react"; import Button from "~/components/Button"; import { useModal } from "~/providers/modal"; import { usePopup } from "~/providers/popup"; import { useWorkspace } from "~/providers/workspace"; import { api } from "~/utils/api"; export function DeleteWorkspaceConfirmation() { const { closeModal } = useModal(); const { workspace, switchWorkspace, availableWorkspaces } = useWorkspace(); const { showPopup } = usePopup(); const router = useRouter(); const [isAcknowledgmentChecked, setIsAcknowledgmentChecked] = useState(false); const deleteWorkspaceMutation = api.workspace.delete.useMutation({ onSuccess: () => { closeModal(); const filteredWorkspaces = availableWorkspaces.filter( (ws) => ws.publicId !== workspace.publicId, ); if (filteredWorkspaces.length > 0 && filteredWorkspaces[0]) { switchWorkspace(filteredWorkspaces[0]); } else { router.push("/"); } }, onError: () => { closeModal(); showPopup({ header: "Error deleting workspace", message: "Please try again later, or contact customer support.", icon: "error", }); }, }); const handleDeleteWorkspace = () => { deleteWorkspaceMutation.mutate({ workspacePublicId: workspace.publicId, }); }; return (

{`Are you sure you want to delete the workspace ${workspace.name}?`}

Keep in mind that this action is irreversible.

This will result in the permanent deletion of all data associated with this workspace.

setIsAcknowledgmentChecked(!isAcknowledgmentChecked) } />

I acknowledge that all of the workspace data will be permanently deleted and want to proceed.

); }