Path: blob/main/components/dashboard/src/dedicated-setup/use-show-dedicated-setup.ts
2506 views
/**1* Copyright (c) 2023 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { useQueryParams } from "../hooks/use-query-params";7import { useCallback, useState } from "react";8import { isCurrentHostExcludedFromSetup, useNeedsSetup } from "./use-needs-setup";9import { useInstallationConfiguration } from "../data/installation/installation-config-query";1011const FORCE_SETUP_PARAM = "dedicated-setup";12const FORCE_SETUP_PARAM_VALUE = "force";1314/**15*16* @description Determines if current user should be shown the dedicated setup flow17*/18export const useShowDedicatedSetup = () => {19// track if user has finished onboarding so we avoid showing the onboarding20// again in case onboarding state isn't updated right away21const [inProgress, setInProgress] = useState(false);2223const { data: installationConfig } = useInstallationConfiguration();24const enableDedicatedOnboardingFlow = !!installationConfig?.isDedicatedInstallation;25const params = useQueryParams();2627const { needsSetup } = useNeedsSetup();2829const forceSetup = forceDedicatedSetupParam(params);30let showSetup = forceSetup || needsSetup;3132if (isCurrentHostExcludedFromSetup()) {33showSetup = false;34}3536const markCompleted = useCallback(() => setInProgress(false), []);3738// Update to inProgress if we should show the setup flow and we aren't39if (enableDedicatedOnboardingFlow && showSetup && !inProgress) {40setInProgress(true);41}4243return {44showSetup: inProgress,45markCompleted,46};47};4849export const forceDedicatedSetupParam = (params: URLSearchParams) => {50return params.get(FORCE_SETUP_PARAM) === FORCE_SETUP_PARAM_VALUE;51};525354