From 091841588755c423811141f2166b7339bccbbd7a Mon Sep 17 00:00:00 2001 From: Xiao Yijun Date: Sat, 18 Mar 2023 21:04:14 +0800 Subject: [PATCH] fix(console): skip onboarding for admin tenant admins (#3489) --- .../containers/TenantAppContainer/index.tsx | 7 +--- .../hooks/use-user-onboarding-data.ts | 39 +++++++++++++++++-- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/packages/console/src/containers/TenantAppContainer/index.tsx b/packages/console/src/containers/TenantAppContainer/index.tsx index ecc0f9424..045b00ee9 100644 --- a/packages/console/src/containers/TenantAppContainer/index.tsx +++ b/packages/console/src/containers/TenantAppContainer/index.tsx @@ -9,17 +9,12 @@ import ConsoleApp from '@/pages/Main'; const TenantAppContainer = () => { const { userEndpoint } = useContext(AppEndpointsContext); - const { - data: { isOnboardingDone }, - isLoaded, - } = useUserOnboardingData(); + const { isOnboarding, isLoaded } = useUserOnboardingData(); if (!userEndpoint || (isCloud && !isLoaded)) { return ; } - const isOnboarding = isCloud && !isOnboardingDone; - if (isOnboarding) { return ; } diff --git a/packages/console/src/onboarding/hooks/use-user-onboarding-data.ts b/packages/console/src/onboarding/hooks/use-user-onboarding-data.ts index ebe18d77d..47666911f 100644 --- a/packages/console/src/onboarding/hooks/use-user-onboarding-data.ts +++ b/packages/console/src/onboarding/hooks/use-user-onboarding-data.ts @@ -1,7 +1,9 @@ -import { useCallback, useMemo } from 'react'; +import { adminTenantId } from '@logto/schemas'; +import { useCallback, useContext, useMemo } from 'react'; import { z } from 'zod'; import { isCloud } from '@/consts/cloud'; +import { TenantsContext } from '@/contexts/TenantsProvider'; import useMeCustomData from '@/hooks/use-me-custom-data'; import type { UserOnboardingData } from '../types'; @@ -11,6 +13,7 @@ const userOnboardingDataKey = 'onboarding'; const useUserOnboardingData = () => { const { data, error, isLoading, isLoaded, update: updateMeCustomData } = useMeCustomData(); + const { currentTenantId } = useContext(TenantsContext); const userOnboardingData = useMemo(() => { const parsed = z.object({ [userOnboardingDataKey]: userOnboardingDataGuard }).safeParse(data); @@ -18,9 +21,29 @@ const useUserOnboardingData = () => { return parsed.success ? parsed.data[userOnboardingDataKey] : {}; }, [data]); + const isOnboarding = useMemo(() => { + if (!isCloud) { + return false; + } + + if (currentTenantId === adminTenantId) { + return false; + } + + return !userOnboardingData.isOnboardingDone; + }, [currentTenantId, userOnboardingData.isOnboardingDone]); + const isBusinessPlan = useMemo(() => { - return isCloud && userOnboardingData.questionnaire?.project === Project.Company; - }, [userOnboardingData]); + if (!isCloud) { + return false; + } + + if (currentTenantId === adminTenantId) { + return true; + } + + return userOnboardingData.questionnaire?.project === Project.Company; + }, [currentTenantId, userOnboardingData.questionnaire?.project]); const update = useCallback( async (data: Partial) => { @@ -34,7 +57,15 @@ const useUserOnboardingData = () => { [updateMeCustomData, userOnboardingData] ); - return { data: userOnboardingData, error, isLoading, isLoaded, isBusinessPlan, update }; + return { + data: userOnboardingData, + error, + isLoading, + isLoaded, + isOnboarding, + isBusinessPlan, + update, + }; }; export default useUserOnboardingData;