Path: blob/main/components/dashboard/src/onboarding/use-show-user-onboarding.ts
2500 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 { useCurrentUser } from "../user-context";7import { useQueryParams } from "../hooks/use-query-params";8import { FORCE_ONBOARDING_PARAM, FORCE_ONBOARDING_PARAM_VALUE } from "./UserOnboarding";9import { isOrganizationOwned } from "@gitpod/public-api-common/lib/user-utils";10import { User } from "@gitpod/public-api/lib/gitpod/v1/user_pb";1112export const useShowUserOnboarding = () => {13const user = useCurrentUser();14const search = useQueryParams();1516if (!user || isOrganizationOwned(user)) {17return false;18}1920// Show new signup flow if:21// * User is onboarding (no ide selected yet, not org user, hasn't onboarded before)22// * OR query param `onboarding=force` is set23const showUserOnboarding =24isOnboardingUser(user) || search.get(FORCE_ONBOARDING_PARAM) === FORCE_ONBOARDING_PARAM_VALUE;2526return showUserOnboarding;27};2829export function hasPreferredIde(user: User) {30return !!user?.editorSettings?.name || !!user?.editorSettings?.version;31}3233export function isOnboardingUser(user: User) {34if (isOrganizationOwned(user)) {35return false;36}37// If a user has already been onboarded38// Also, used to rule out "admin-user"39if (!!user.profile?.onboardedTimestamp) {40return false;41}42return !hasPreferredIde(user);43}444546