From ad638461c30391bedb212dc887b97a8d4028c5df Mon Sep 17 00:00:00 2001 From: shivam-bit Date: Mon, 22 Apr 2024 11:21:26 +0530 Subject: [PATCH] Update useRoute.ts and ThirdPartyAuthContext.tsx --- web-server/src/constants/useRoute.ts | 31 ++++++++++++++++--- .../src/contexts/ThirdPartyAuthContext.tsx | 5 ++- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/web-server/src/constants/useRoute.ts b/web-server/src/constants/useRoute.ts index d8ceaf06a..473ea00a0 100644 --- a/web-server/src/constants/useRoute.ts +++ b/web-server/src/constants/useRoute.ts @@ -2,7 +2,7 @@ import { useRouter } from 'next/router'; import { useEffect } from 'react'; import { useAuth } from '@/hooks/useAuth'; -import { UserRole } from '@/types/resources'; +import { OnboardingSteps, UserRole } from '@/types/resources'; import { ROUTES } from './routes'; @@ -13,19 +13,40 @@ export const useDefaultRoute = () => { export const useRedirectWithSession = () => { const defaultRoute = useDefaultRoute(); const router = useRouter(); - const { org, orgId } = useAuth(); - const isOrgWelcomed = org?.onboarding_steps?.includes( - OnboardingStep.WELCOME_SCREEN + const { org, orgId, onboardingState } = useAuth(); + + const isOrgWelcomed = onboardingState.includes( + OnboardingSteps.WELCOME_SCREEN + ); + + const anyTeamEverExisted = onboardingState.includes( + OnboardingSteps.TEAM_CREATED ); + const isOneCodeProviderIntegrated = + org?.integrations?.github || + org?.integrations?.gitlab || + org?.integrations?.bitbucket; + useEffect(() => { if (!orgId) return; if (!isOrgWelcomed) { router.replace(ROUTES.WELCOME.PATH); return; } + if (!isOneCodeProviderIntegrated || !anyTeamEverExisted) { + router.replace(ROUTES.INTEGRATIONS.PATH); + return; + } router.replace(defaultRoute.PATH); - }, [defaultRoute.PATH, isOrgWelcomed, orgId, router]); + }, [ + anyTeamEverExisted, + defaultRoute.PATH, + isOneCodeProviderIntegrated, + isOrgWelcomed, + orgId, + router + ]); }; const roleList = [UserRole.ENGINEER, UserRole.EM, UserRole.MOM]; diff --git a/web-server/src/contexts/ThirdPartyAuthContext.tsx b/web-server/src/contexts/ThirdPartyAuthContext.tsx index ad29352e4..e8674e127 100644 --- a/web-server/src/contexts/ThirdPartyAuthContext.tsx +++ b/web-server/src/contexts/ThirdPartyAuthContext.tsx @@ -18,6 +18,7 @@ export interface AuthContextValue extends AuthState { orgId: string | null; role: UserRole; integrations: User['integrations']; + onboardingState: OnboardingStep[]; integrationSet: Set; } @@ -26,6 +27,7 @@ export const AuthContext = createContext({ orgId: null, role: UserRole.MOM, integrations: {}, + onboardingState: [], integrationSet: new Set() }); @@ -114,7 +116,8 @@ export const AuthProvider: FC = (props) => { orgId: state.org?.id, role, integrations, - integrationSet + integrationSet, + onboardingState: state.org?.onboarding_state || [] }} > {children}