1
1
import { MissingBuildParameters } from "api/api" ;
2
+ import { isApiError } from "api/errors" ;
3
+ import { type ApiError , getErrorMessage } from "api/errors" ;
2
4
import {
3
5
changeVersion ,
4
6
deleteWorkspace ,
@@ -13,6 +15,7 @@ import {
13
15
DropdownMenuSeparator ,
14
16
DropdownMenuTrigger ,
15
17
} from "components/DropdownMenu/DropdownMenu" ;
18
+ import { displayError } from "components/GlobalSnackbar/utils" ;
16
19
import {
17
20
CopyIcon ,
18
21
DownloadIcon ,
@@ -24,6 +27,7 @@ import {
24
27
import { type FC , useEffect , useState } from "react" ;
25
28
import { useMutation , useQuery , useQueryClient } from "react-query" ;
26
29
import { Link as RouterLink } from "react-router-dom" ;
30
+ import { WorkspaceErrorDialog } from "../ErrorDialog/WorkspaceErrorDialog" ;
27
31
import { ChangeWorkspaceVersionDialog } from "./ChangeWorkspaceVersionDialog" ;
28
32
import { DownloadLogsDialog } from "./DownloadLogsDialog" ;
29
33
import { UpdateBuildParametersDialog } from "./UpdateBuildParametersDialog" ;
@@ -42,6 +46,11 @@ export const WorkspaceMoreActions: FC<WorkspaceMoreActionsProps> = ({
42
46
} ) => {
43
47
const queryClient = useQueryClient ( ) ;
44
48
49
+ const [ workspaceErrorDialog , setWorkspaceErrorDialog ] = useState < {
50
+ open :boolean ;
51
+ error ?:ApiError ;
52
+ } > ( { open :false } ) ;
53
+
45
54
// Permissions
46
55
const { data :permissions } = useQuery ( workspacePermissions ( workspace ) ) ;
47
56
@@ -58,11 +67,25 @@ export const WorkspaceMoreActions: FC<WorkspaceMoreActionsProps> = ({
58
67
) ,
59
68
) ;
60
69
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
+
61
81
// Delete
62
82
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
+ } ) ;
66
89
67
90
// Duplicate
68
91
const { duplicateWorkspace, isDuplicationReady} =
@@ -212,6 +235,17 @@ export const WorkspaceMoreActions: FC<WorkspaceMoreActionsProps> = ({
212
235
setIsConfirmingDelete ( false ) ;
213
236
} }
214
237
/>
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
+ />
215
249
</ >
216
250
) ;
217
251
} ;