Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/app/AppBlockingFlows.tsx
2499 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 { FC, lazy } from "react";
8
import { useShowDedicatedSetup } from "../dedicated-setup/use-show-dedicated-setup";
9
import { useCurrentUser } from "../user-context";
10
import { useShowUserOnboarding } from "../onboarding/use-show-user-onboarding";
11
import { useHistory } from "react-router";
12
import { useCurrentOrg } from "../data/organizations/orgs-query";
13
import { OrgNamingStep } from "../dedicated-setup/OrgNamingStep";
14
15
const UserOnboarding = lazy(() => import(/* webpackPrefetch: true */ "../onboarding/UserOnboarding"));
16
const DedicatedSetup = lazy(() => import(/* webpackPrefetch: true */ "../dedicated-setup/DedicatedSetup"));
17
18
// This component handles any flows that should come after we've loaded the user/orgs, but before we render the normal app chrome.
19
// Since this runs before the app is rendered, we should avoid adding any lengthy async calls that would delay the app from loading.
20
export const AppBlockingFlows: FC = ({ children }) => {
21
const history = useHistory();
22
const user = useCurrentUser();
23
const org = useCurrentOrg();
24
const showDedicatedSetup = useShowDedicatedSetup();
25
const showUserOnboarding = useShowUserOnboarding();
26
27
// This shouldn't happen, but if it does don't render anything yet
28
if (!user) {
29
return <></>;
30
}
31
32
// Handle dedicated setup if necessary
33
if (showDedicatedSetup.showSetup) {
34
return (
35
<DedicatedSetup
36
onComplete={() => {
37
showDedicatedSetup.markCompleted();
38
// keep this here to avoid flashing a different page while we reload below
39
history.push("/settings/git");
40
// doing a full page reload here to avoid any lingering setup-related state issues
41
document.location.href = "/settings/git";
42
}}
43
/>
44
);
45
}
46
47
// New user onboarding flow
48
if (showUserOnboarding) {
49
return <UserOnboarding user={user} />;
50
}
51
52
if (!org.data) {
53
return <OrgNamingStep onComplete={() => {}} />;
54
}
55
56
return <>{children}</>;
57
};
58
59