import { useRouter } from "next/router"; import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider"; import { ProjectPermissionCan } from "@app/components/permissions"; import { Button, DeleteActionModal } from "@app/components/v2"; import { ProjectPermissionActions, ProjectPermissionSub, useOrganization, useWorkspace } from "@app/context"; import { useToggle } from "@app/hooks"; import { useDeleteWorkspace } from "@app/hooks/api"; import { usePopUp } from "@app/hooks/usePopUp"; export const DeleteProjectSection = () => { const router = useRouter(); const { createNotification } = useNotificationContext(); const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ "deleteWorkspace" ] as const); const { currentOrg } = useOrganization(); const { currentWorkspace } = useWorkspace(); const [isDeleting, setIsDeleting] = useToggle(); const deleteWorkspace = useDeleteWorkspace(); const handleDeleteWorkspaceSubmit = async () => { setIsDeleting.on(); try { if (!currentWorkspace?.id) return; await deleteWorkspace.mutateAsync({ workspaceID: currentWorkspace?.id }); createNotification({ text: "Successfully deleted project", type: "success" }); router.push(`/org/${currentOrg?.id}/overview`); handlePopUpClose("deleteWorkspace"); } catch (err) { console.error(err); createNotification({ text: "Failed to delete project", type: "error" }); } finally { setIsDeleting.off(); } }; return (
Danger Zone