Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/onboarding/use-show-user-onboarding.ts
2500 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 { useCurrentUser } from "../user-context";
8
import { useQueryParams } from "../hooks/use-query-params";
9
import { FORCE_ONBOARDING_PARAM, FORCE_ONBOARDING_PARAM_VALUE } from "./UserOnboarding";
10
import { isOrganizationOwned } from "@gitpod/public-api-common/lib/user-utils";
11
import { User } from "@gitpod/public-api/lib/gitpod/v1/user_pb";
12
13
export const useShowUserOnboarding = () => {
14
const user = useCurrentUser();
15
const search = useQueryParams();
16
17
if (!user || isOrganizationOwned(user)) {
18
return false;
19
}
20
21
// Show new signup flow if:
22
// * User is onboarding (no ide selected yet, not org user, hasn't onboarded before)
23
// * OR query param `onboarding=force` is set
24
const showUserOnboarding =
25
isOnboardingUser(user) || search.get(FORCE_ONBOARDING_PARAM) === FORCE_ONBOARDING_PARAM_VALUE;
26
27
return showUserOnboarding;
28
};
29
30
export function hasPreferredIde(user: User) {
31
return !!user?.editorSettings?.name || !!user?.editorSettings?.version;
32
}
33
34
export function isOnboardingUser(user: User) {
35
if (isOrganizationOwned(user)) {
36
return false;
37
}
38
// If a user has already been onboarded
39
// Also, used to rule out "admin-user"
40
if (!!user.profile?.onboardedTimestamp) {
41
return false;
42
}
43
return !hasPreferredIde(user);
44
}
45
46