Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/dedicated-setup/use-show-dedicated-setup.ts
2506 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { useQueryParams } from "../hooks/use-query-params";
8
import { useCallback, useState } from "react";
9
import { isCurrentHostExcludedFromSetup, useNeedsSetup } from "./use-needs-setup";
10
import { useInstallationConfiguration } from "../data/installation/installation-config-query";
11
12
const FORCE_SETUP_PARAM = "dedicated-setup";
13
const FORCE_SETUP_PARAM_VALUE = "force";
14
15
/**
16
*
17
* @description Determines if current user should be shown the dedicated setup flow
18
*/
19
export const useShowDedicatedSetup = () => {
20
// track if user has finished onboarding so we avoid showing the onboarding
21
// again in case onboarding state isn't updated right away
22
const [inProgress, setInProgress] = useState(false);
23
24
const { data: installationConfig } = useInstallationConfiguration();
25
const enableDedicatedOnboardingFlow = !!installationConfig?.isDedicatedInstallation;
26
const params = useQueryParams();
27
28
const { needsSetup } = useNeedsSetup();
29
30
const forceSetup = forceDedicatedSetupParam(params);
31
let showSetup = forceSetup || needsSetup;
32
33
if (isCurrentHostExcludedFromSetup()) {
34
showSetup = false;
35
}
36
37
const markCompleted = useCallback(() => setInProgress(false), []);
38
39
// Update to inProgress if we should show the setup flow and we aren't
40
if (enableDedicatedOnboardingFlow && showSetup && !inProgress) {
41
setInProgress(true);
42
}
43
44
return {
45
showSetup: inProgress,
46
markCompleted,
47
};
48
};
49
50
export const forceDedicatedSetupParam = (params: URLSearchParams) => {
51
return params.get(FORCE_SETUP_PARAM) === FORCE_SETUP_PARAM_VALUE;
52
};
53
54