Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 1 addition & 46 deletions site/src/pages/CreateWorkspacePage/CreateWorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { checkAuthorization } from "#/api/queries/authCheck";
import {
templateByName,
templateVersion,
templateVersionExternalAuth,
templateVersionPresets,
} from "#/api/queries/templates";
import { autoCreateWorkspace, createWorkspace } from "#/api/queries/workspaces";
Expand All @@ -28,6 +27,7 @@ import type {
} from "#/api/typesGenerated";
import { Loader } from "#/components/Loader/Loader";
import { useAuthenticated } from "#/hooks/useAuthenticated";
import { useExternalAuth } from "#/hooks/useExternalAuth";
import { getInitialParameterValues } from "#/modules/workspaces/DynamicParameter/DynamicParameter";
import { generateWorkspaceName } from "#/modules/workspaces/generateWorkspaceName";
import { pageTitle } from "#/utils/page";
Expand All @@ -41,7 +41,6 @@ import {

const createWorkspaceModes = ["form", "auto", "duplicate"] as const;
export type CreateWorkspaceMode = (typeof createWorkspaceModes)[number];
type ExternalAuthPollingState = "idle" | "polling" | "abandoned";

const CreateWorkspacePage: FC = () => {
const { organization: organizationName = "default", template: templateName } =
Expand Down Expand Up @@ -461,50 +460,6 @@ const CreateWorkspacePage: FC = () => {
);
};

const useExternalAuth = (versionId: string | undefined) => {
const [externalAuthPollingState, setExternalAuthPollingState] =
useState<ExternalAuthPollingState>("idle");

const startPollingExternalAuth = useCallback(() => {
setExternalAuthPollingState("polling");
}, []);

const { data: externalAuth, isLoading: isLoadingExternalAuth } = useQuery({
...templateVersionExternalAuth(versionId ?? ""),
enabled: Boolean(versionId),
refetchInterval: externalAuthPollingState === "polling" ? 1000 : false,
});

const allSignedIn = externalAuth?.every((it) => it.authenticated);

useEffect(() => {
if (allSignedIn) {
setExternalAuthPollingState("idle");
return;
}

if (externalAuthPollingState !== "polling") {
return;
}

// Poll for a maximum of one minute
const quitPolling = setTimeout(
() => setExternalAuthPollingState("abandoned"),
60_000,
);
return () => {
clearTimeout(quitPolling);
};
}, [externalAuthPollingState, allSignedIn]);

return {
startPollingExternalAuth,
externalAuth,
externalAuthPollingState,
isLoadingExternalAuth,
};
};

const getAutofillParameters = (
urlSearchParams: URLSearchParams,
): AutofillBuildParameter[] => {
Expand Down
Loading