Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions web-server/src/constants/useRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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];
Expand Down
5 changes: 4 additions & 1 deletion web-server/src/contexts/ThirdPartyAuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface AuthContextValue extends AuthState {
orgId: string | null;
role: UserRole;
integrations: User['integrations'];
onboardingState: OnboardingStep[];
integrationSet: Set<IntegrationGroup>;
}

Expand All @@ -26,6 +27,7 @@ export const AuthContext = createContext<AuthContextValue>({
orgId: null,
role: UserRole.MOM,
integrations: {},
onboardingState: [],
integrationSet: new Set()
});

Expand Down Expand Up @@ -114,7 +116,8 @@ export const AuthProvider: FC = (props) => {
orgId: state.org?.id,
role,
integrations,
integrationSet
integrationSet,
onboardingState: state.org?.onboarding_state || []
}}
>
{children}
Expand Down