diff --git a/components/dashboard/src/data/workspaces/create-workspace-mutation.ts b/components/dashboard/src/data/workspaces/create-workspace-mutation.ts new file mode 100644 index 00000000000000..1d20ef30221216 --- /dev/null +++ b/components/dashboard/src/data/workspaces/create-workspace-mutation.ts @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2023 Gitpod GmbH. All rights reserved. + * Licensed under the GNU Affero General Public License (AGPL). + * See License.AGPL.txt in the project root for license information. + */ + +import { GitpodServer } from "@gitpod/gitpod-protocol"; +import { useMutation } from "@tanstack/react-query"; +import { getGitpodService } from "../../service/service"; + +export const useCreateWorkspaceMutation = () => { + return useMutation({ + mutationFn: async (options: GitpodServer.CreateWorkspaceOptions) => { + return await getGitpodService().server.createWorkspace(options); + }, + }); +}; diff --git a/components/dashboard/src/workspaces/CreateWorkspacePage.tsx b/components/dashboard/src/workspaces/CreateWorkspacePage.tsx index 41b3b578313a0a..28dd7959d82f8a 100644 --- a/components/dashboard/src/workspaces/CreateWorkspacePage.tsx +++ b/components/dashboard/src/workspaces/CreateWorkspacePage.tsx @@ -10,13 +10,13 @@ import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred"; import { FunctionComponent, useCallback, useState } from "react"; import { useHistory, useLocation } from "react-router"; -import Modal from "../components/Modal"; +import Modal, { ModalBody, ModalFooter, ModalHeader } from "../components/Modal"; import RepositoryFinder from "../components/RepositoryFinder"; import SelectIDEComponent from "../components/SelectIDEComponent"; import SelectWorkspaceClassComponent from "../components/SelectWorkspaceClassComponent"; import { UsageLimitReachedModal } from "../components/UsageLimitReachedModal"; import { openAuthorizeWindow } from "../provider-utils"; -import { getGitpodService, gitpodHostUrl } from "../service/service"; +import { gitpodHostUrl } from "../service/service"; import { LimitReachedOutOfHours, LimitReachedParallelWorkspacesModal } from "../start/CreateWorkspace"; import { StartWorkspaceOptions } from "../start/start-workspace-options"; import { StartWorkspaceError } from "../start/StartPage"; @@ -25,6 +25,7 @@ import { SelectAccountModal } from "../user-settings/SelectAccountModal"; import Spinner from "../icons/Spinner.svg"; import { useFeatureFlags } from "../contexts/FeatureFlagContext"; import { useCurrentTeam } from "../teams/teams-context"; +import { useCreateWorkspaceMutation } from "../data/workspaces/create-workspace-mutation"; export const useNewCreateWorkspacePage = () => { const { startWithOptions } = useFeatureFlags(); @@ -38,6 +39,7 @@ export function CreateWorkspacePage() { const location = useLocation(); const history = useHistory(); const props = StartWorkspaceOptions.parseSearchParams(location.search); + const createWorkspaceMutation = useCreateWorkspaceMutation(); const [useLatestIde, setUseLatestIde] = useState( props.ideSettings?.useLatestVersion !== undefined @@ -60,10 +62,8 @@ export function CreateWorkspacePage() { [setSelectedIde, setUseLatestIde], ); const [errorIde, setErrorIde] = useState(undefined); - const [creating, setCreating] = useState(false); const [existingWorkspaces, setExistingWorkspaces] = useState([]); - const [createError, setCreateError] = useState(undefined); const [selectAccountError, setSelectAccountError] = useState(undefined); const createWorkspace = useCallback( @@ -85,8 +85,7 @@ export function CreateWorkspacePage() { } try { - setCreating(true); - const result = await getGitpodService().server.createWorkspace({ + const result = await createWorkspaceMutation.mutateAsync({ contextUrl: repo, organizationId: team?.id, ...opts, @@ -99,12 +98,10 @@ export function CreateWorkspacePage() { setExistingWorkspaces(result.existingWorkspaces); } } catch (error) { - setCreateError(error); - } finally { - setCreating(false); + console.log(error); } }, - [history, repo, selectedIde, selectedWsClass, team?.id, useLatestIde], + [createWorkspaceMutation, history, repo, selectedIde, selectedWsClass, team?.id, useLatestIde], ); const onClickCreate = useCallback(() => createWorkspace(), [createWorkspace]); @@ -119,15 +116,6 @@ export function CreateWorkspacePage() { /> ); } - if (existingWorkspaces.length > 0) { - return ( - {}} - /> - ); - } return (
@@ -161,9 +149,15 @@ export function CreateWorkspacePage() {
+ {existingWorkspaces.length > 0 && ( + setExistingWorkspaces([])} + /> + )}
); } @@ -307,8 +308,8 @@ const ExistingWorkspaceModal: FunctionComponent = ( }) => { return ( -

Running Workspaces

-
+ Running Workspaces +

You already have running workspaces with the same context. You can open an existing one or open a new workspace. @@ -335,12 +336,15 @@ const ExistingWorkspaceModal: FunctionComponent = ( ); })} -

-
+ + + -
+
); };