0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

fix(console): skip onboarding for admin tenant admins (#3489)

This commit is contained in:
Xiao Yijun 2023-03-18 21:04:14 +08:00 committed by GitHub
parent 97985da522
commit 0918415887
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 10 deletions

View file

@ -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 <AppLoading />;
}
const isOnboarding = isCloud && !isOnboardingDone;
if (isOnboarding) {
return <OnboardingApp />;
}

View file

@ -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<UserOnboardingData>) => {
@ -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;