@@ -10,13 +10,13 @@ import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
10
10
import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred" ;
11
11
import { FunctionComponent , useCallback , useState } from "react" ;
12
12
import { useHistory , useLocation } from "react-router" ;
13
- import Modal from "../components/Modal" ;
13
+ import Modal , { ModalBody , ModalFooter , ModalHeader } from "../components/Modal" ;
14
14
import RepositoryFinder from "../components/RepositoryFinder" ;
15
15
import SelectIDEComponent from "../components/SelectIDEComponent" ;
16
16
import SelectWorkspaceClassComponent from "../components/SelectWorkspaceClassComponent" ;
17
17
import { UsageLimitReachedModal } from "../components/UsageLimitReachedModal" ;
18
18
import { openAuthorizeWindow } from "../provider-utils" ;
19
- import { getGitpodService , gitpodHostUrl } from "../service/service" ;
19
+ import { gitpodHostUrl } from "../service/service" ;
20
20
import { LimitReachedOutOfHours , LimitReachedParallelWorkspacesModal } from "../start/CreateWorkspace" ;
21
21
import { StartWorkspaceOptions } from "../start/start-workspace-options" ;
22
22
import { StartWorkspaceError } from "../start/StartPage" ;
@@ -25,6 +25,7 @@ import { SelectAccountModal } from "../user-settings/SelectAccountModal";
25
25
import Spinner from "../icons/Spinner.svg" ;
26
26
import { useFeatureFlags } from "../contexts/FeatureFlagContext" ;
27
27
import { useCurrentTeam } from "../teams/teams-context" ;
28
+ import { useCreateWorkspaceMutation } from "../data/workspaces/create-workspace-mutation" ;
28
29
29
30
export const useNewCreateWorkspacePage = ( ) => {
30
31
const { startWithOptions } = useFeatureFlags ( ) ;
@@ -38,6 +39,7 @@ export function CreateWorkspacePage() {
38
39
const location = useLocation ( ) ;
39
40
const history = useHistory ( ) ;
40
41
const props = StartWorkspaceOptions . parseSearchParams ( location . search ) ;
42
+ const createWorkspaceMutation = useCreateWorkspaceMutation ( ) ;
41
43
42
44
const [ useLatestIde , setUseLatestIde ] = useState (
43
45
props . ideSettings ?. useLatestVersion !== undefined
@@ -60,10 +62,8 @@ export function CreateWorkspacePage() {
60
62
[ setSelectedIde , setUseLatestIde ] ,
61
63
) ;
62
64
const [ errorIde , setErrorIde ] = useState < string | undefined > ( undefined ) ;
63
- const [ creating , setCreating ] = useState ( false ) ;
64
65
65
66
const [ existingWorkspaces , setExistingWorkspaces ] = useState < WorkspaceInfo [ ] > ( [ ] ) ;
66
- const [ createError , setCreateError ] = useState < StartWorkspaceError | undefined > ( undefined ) ;
67
67
const [ selectAccountError , setSelectAccountError ] = useState < SelectAccountPayload | undefined > ( undefined ) ;
68
68
69
69
const createWorkspace = useCallback (
@@ -85,8 +85,7 @@ export function CreateWorkspacePage() {
85
85
}
86
86
87
87
try {
88
- setCreating ( true ) ;
89
- const result = await getGitpodService ( ) . server . createWorkspace ( {
88
+ const result = await createWorkspaceMutation . mutateAsync ( {
90
89
contextUrl : repo ,
91
90
organizationId : team ?. id ,
92
91
...opts ,
@@ -99,12 +98,10 @@ export function CreateWorkspacePage() {
99
98
setExistingWorkspaces ( result . existingWorkspaces ) ;
100
99
}
101
100
} catch ( error ) {
102
- setCreateError ( error ) ;
103
- } finally {
104
- setCreating ( false ) ;
101
+ console . log ( error ) ;
105
102
}
106
103
} ,
107
- [ history , repo , selectedIde , selectedWsClass , team ?. id , useLatestIde ] ,
104
+ [ createWorkspaceMutation , history , repo , selectedIde , selectedWsClass , team ?. id , useLatestIde ] ,
108
105
) ;
109
106
110
107
const onClickCreate = useCallback ( ( ) => createWorkspace ( ) , [ createWorkspace ] ) ;
@@ -119,15 +116,6 @@ export function CreateWorkspacePage() {
119
116
/>
120
117
) ;
121
118
}
122
- if ( existingWorkspaces . length > 0 ) {
123
- return (
124
- < ExistingWorkspaceModal
125
- existingWorkspaces = { existingWorkspaces }
126
- createWorkspace = { createWorkspace }
127
- onClose = { ( ) => { } }
128
- />
129
- ) ;
130
- }
131
119
132
120
return (
133
121
< div className = "flex flex-col mt-32 mx-auto " >
@@ -161,9 +149,15 @@ export function CreateWorkspacePage() {
161
149
< div className = "w-full flex justify-end mt-6 space-x-2 px-6" >
162
150
< button
163
151
onClick = { onClickCreate }
164
- disabled = { creating || ! repo || repo . length === 0 || ! ! errorIde || ! ! errorWsClass }
152
+ disabled = {
153
+ createWorkspaceMutation . isLoading ||
154
+ ! repo ||
155
+ repo . length === 0 ||
156
+ ! ! errorIde ||
157
+ ! ! errorWsClass
158
+ }
165
159
>
166
- { creating ? (
160
+ { createWorkspaceMutation . isLoading ? (
167
161
< div className = "flex" >
168
162
< img className = "h-4 w-4 animate-spin" src = { Spinner } alt = "loading spinner" />
169
163
< span className = "pl-2" > Creating Workspace ...</ span >
@@ -175,12 +169,19 @@ export function CreateWorkspacePage() {
175
169
</ div >
176
170
< div >
177
171
< StatusMessage
178
- error = { createError }
172
+ error = { createWorkspaceMutation . error as StartWorkspaceError }
179
173
setSelectAccountError = { setSelectAccountError }
180
174
createWorkspace = { createWorkspace }
181
175
/>
182
176
</ div >
183
177
</ div >
178
+ { existingWorkspaces . length > 0 && (
179
+ < ExistingWorkspaceModal
180
+ existingWorkspaces = { existingWorkspaces }
181
+ createWorkspace = { createWorkspace }
182
+ onClose = { ( ) => setExistingWorkspaces ( [ ] ) }
183
+ />
184
+ ) }
184
185
</ div >
185
186
) ;
186
187
}
@@ -307,8 +308,8 @@ const ExistingWorkspaceModal: FunctionComponent<ExistingWorkspaceModalProps> = (
307
308
} ) => {
308
309
return (
309
310
< Modal visible = { true } closeable = { true } onClose = { onClose } >
310
- < h3 > Running Workspaces</ h3 >
311
- < div className = "border-t border-b border-gray-200 dark:border-gray-800 mt-4 -mx-6 px-6 py-2" >
311
+ < ModalHeader > Running Workspaces</ ModalHeader >
312
+ < ModalBody >
312
313
< p className = "mt-1 mb-2 text-base" >
313
314
You already have running workspaces with the same context. You can open an existing one or open a
314
315
new workspace.
@@ -335,12 +336,15 @@ const ExistingWorkspaceModal: FunctionComponent<ExistingWorkspaceModalProps> = (
335
336
) ;
336
337
} ) }
337
338
</ >
338
- </ div >
339
- < div className = "flex justify-end mt-6" >
339
+ </ ModalBody >
340
+ < ModalFooter >
341
+ < button className = "secondary" onClick = { onClose } >
342
+ Cancel
343
+ </ button >
340
344
< button onClick = { ( ) => createWorkspace ( { ignoreRunningWorkspaceOnSameCommit : true } ) } >
341
345
New Workspace
342
346
</ button >
343
- </ div >
347
+ </ ModalFooter >
344
348
</ Modal >
345
349
) ;
346
350
} ;
0 commit comments