Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/workspaces/DeleteWorkspaceModal.tsx
2500 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { FunctionComponent, useCallback } from "react";
8
import ConfirmationModal from "../components/ConfirmationModal";
9
import { useDeleteWorkspaceMutation } from "../data/workspaces/delete-workspace-mutation";
10
import { useToast } from "../components/toasts/Toasts";
11
import { Workspace } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
12
import { fromWorkspaceName } from "./RenameWorkspaceModal";
13
14
type Props = {
15
workspace: Workspace;
16
onClose(): void;
17
};
18
export const DeleteWorkspaceModal: FunctionComponent<Props> = ({ workspace, onClose }) => {
19
const deleteWorkspace = useDeleteWorkspaceMutation();
20
const { toast } = useToast();
21
22
const handleConfirmation = useCallback(async () => {
23
try {
24
await deleteWorkspace.mutateAsync({ workspaceId: workspace.id });
25
26
toast("Your workspace was deleted");
27
onClose();
28
} catch (e) {}
29
}, [deleteWorkspace, onClose, toast, workspace.id]);
30
31
return (
32
<ConfirmationModal
33
title="Delete Workspace"
34
areYouSureText="Are you sure you want to delete this workspace?"
35
children={{
36
name: workspace.id,
37
description: fromWorkspaceName(workspace),
38
}}
39
buttonText="Delete Workspace"
40
warningText={deleteWorkspace.isError ? "There was a problem deleting your workspace." : undefined}
41
onClose={onClose}
42
onConfirm={handleConfirmation}
43
visible
44
/>
45
);
46
};
47
48