Skip to content

Commit ad67733

Browse files
authored
fix: display error message on delete workspace error (#18654)
resolves coder/preview#155 When deleting a workspace, show an error dialog if deleting the workspace is not possible. ![Screenshot 2025-06-28 at 10 06 47](https://github.com/user-attachments/assets/650bfb54-6ed9-4f41-a410-1333afeee0a4)
1 parent 22c5e84 commit ad67733

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

site/src/modules/workspaces/ErrorDialog/WorkspaceErrorDialog.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface WorkspaceErrorDialogProps {
1919
workspaceOwner: string;
2020
workspaceName: string;
2121
templateVersionId: string;
22+
isDeleting: boolean;
2223
}
2324

2425
export const WorkspaceErrorDialog: FC<WorkspaceErrorDialogProps> = ({
@@ -29,6 +30,7 @@ export const WorkspaceErrorDialog: FC<WorkspaceErrorDialogProps> = ({
2930
workspaceOwner,
3031
workspaceName,
3132
templateVersionId,
33+
isDeleting,
3234
}) => {
3335
const navigate = useNavigate();
3436

@@ -52,7 +54,9 @@ export const WorkspaceErrorDialog: FC<WorkspaceErrorDialogProps> = ({
5254
<Dialog open={open} onOpenChange={(isOpen) => !isOpen && onClose()}>
5355
<DialogContent variant="destructive">
5456
<DialogHeader>
55-
<DialogTitle>Error building workspace</DialogTitle>
57+
<DialogTitle>
58+
Error {isDeleting ? "deleting" : "building"} workspace
59+
</DialogTitle>
5660
<DialogDescription className="flex flex-row gap-4">
5761
<strong className="text-content-primary">Message</strong>{" "}
5862
<span>{getErrorMessage(error, "Failed to build workspace.")}</span>

site/src/modules/workspaces/WorkspaceMoreActions/WorkspaceMoreActions.tsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { MissingBuildParameters } from "api/api";
2+
import { isApiError } from "api/errors";
3+
import { type ApiError, getErrorMessage } from "api/errors";
24
import {
35
changeVersion,
46
deleteWorkspace,
@@ -13,6 +15,7 @@ import {
1315
DropdownMenuSeparator,
1416
DropdownMenuTrigger,
1517
} from "components/DropdownMenu/DropdownMenu";
18+
import { displayError } from "components/GlobalSnackbar/utils";
1619
import {
1720
CopyIcon,
1821
DownloadIcon,
@@ -24,6 +27,7 @@ import {
2427
import { type FC, useEffect, useState } from "react";
2528
import { useMutation, useQuery, useQueryClient } from "react-query";
2629
import { Link as RouterLink } from "react-router-dom";
30+
import { WorkspaceErrorDialog } from "../ErrorDialog/WorkspaceErrorDialog";
2731
import { ChangeWorkspaceVersionDialog } from "./ChangeWorkspaceVersionDialog";
2832
import { DownloadLogsDialog } from "./DownloadLogsDialog";
2933
import { UpdateBuildParametersDialog } from "./UpdateBuildParametersDialog";
@@ -42,6 +46,11 @@ export const WorkspaceMoreActions: FC<WorkspaceMoreActionsProps> = ({
4246
}) => {
4347
const queryClient = useQueryClient();
4448

49+
const [workspaceErrorDialog, setWorkspaceErrorDialog] = useState<{
50+
open: boolean;
51+
error?: ApiError;
52+
}>({ open: false });
53+
4554
// Permissions
4655
const { data: permissions } = useQuery(workspacePermissions(workspace));
4756

@@ -58,11 +67,25 @@ export const WorkspaceMoreActions: FC<WorkspaceMoreActionsProps> = ({
5867
),
5968
);
6069

70+
const handleError = (error: unknown) => {
71+
if (isApiError(error) && error.code === "ERR_BAD_REQUEST") {
72+
setWorkspaceErrorDialog({
73+
open: true,
74+
error: error,
75+
});
76+
} else {
77+
displayError(getErrorMessage(error, "Failed to delete workspace."));
78+
}
79+
};
80+
6181
// Delete
6282
const [isConfirmingDelete, setIsConfirmingDelete] = useState(false);
63-
const deleteWorkspaceMutation = useMutation(
64-
deleteWorkspace(workspace, queryClient),
65-
);
83+
const deleteWorkspaceMutation = useMutation({
84+
...deleteWorkspace(workspace, queryClient),
85+
onError: (error: unknown) => {
86+
handleError(error);
87+
},
88+
});
6689

6790
// Duplicate
6891
const { duplicateWorkspace, isDuplicationReady } =
@@ -212,6 +235,17 @@ export const WorkspaceMoreActions: FC<WorkspaceMoreActionsProps> = ({
212235
setIsConfirmingDelete(false);
213236
}}
214237
/>
238+
239+
<WorkspaceErrorDialog
240+
open={workspaceErrorDialog.open}
241+
error={workspaceErrorDialog.error}
242+
onClose={() => setWorkspaceErrorDialog({ open: false })}
243+
showDetail={workspace.template_use_classic_parameter_flow}
244+
workspaceOwner={workspace.owner_name}
245+
workspaceName={workspace.name}
246+
templateVersionId={workspace.latest_build.template_version_id}
247+
isDeleting={true}
248+
/>
215249
</>
216250
);
217251
};

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({
392392
workspaceOwner={workspace.owner_name}
393393
workspaceName={workspace.name}
394394
templateVersionId={workspace.latest_build.template_version_id}
395+
isDeleting={false}
395396
/>
396397
</>
397398
);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy