Path: blob/main/components/dashboard/src/app/AppBlockingFlows.tsx
2499 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 { FC, lazy } from "react";7import { useShowDedicatedSetup } from "../dedicated-setup/use-show-dedicated-setup";8import { useCurrentUser } from "../user-context";9import { useShowUserOnboarding } from "../onboarding/use-show-user-onboarding";10import { useHistory } from "react-router";11import { useCurrentOrg } from "../data/organizations/orgs-query";12import { OrgNamingStep } from "../dedicated-setup/OrgNamingStep";1314const UserOnboarding = lazy(() => import(/* webpackPrefetch: true */ "../onboarding/UserOnboarding"));15const DedicatedSetup = lazy(() => import(/* webpackPrefetch: true */ "../dedicated-setup/DedicatedSetup"));1617// This component handles any flows that should come after we've loaded the user/orgs, but before we render the normal app chrome.18// Since this runs before the app is rendered, we should avoid adding any lengthy async calls that would delay the app from loading.19export const AppBlockingFlows: FC = ({ children }) => {20const history = useHistory();21const user = useCurrentUser();22const org = useCurrentOrg();23const showDedicatedSetup = useShowDedicatedSetup();24const showUserOnboarding = useShowUserOnboarding();2526// This shouldn't happen, but if it does don't render anything yet27if (!user) {28return <></>;29}3031// Handle dedicated setup if necessary32if (showDedicatedSetup.showSetup) {33return (34<DedicatedSetup35onComplete={() => {36showDedicatedSetup.markCompleted();37// keep this here to avoid flashing a different page while we reload below38history.push("/settings/git");39// doing a full page reload here to avoid any lingering setup-related state issues40document.location.href = "/settings/git";41}}42/>43);44}4546// New user onboarding flow47if (showUserOnboarding) {48return <UserOnboarding user={user} />;49}5051if (!org.data) {52return <OrgNamingStep onComplete={() => {}} />;53}5455return <>{children}</>;56};575859