From 146450848a13fe15b906a4bdff240577c162dae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bonnet?= Date: Thu, 22 Dec 2022 11:19:11 +0100 Subject: [PATCH] fix(use-redirect): redirect onboarding --- .../use-redirect-if-logged.tsx | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/libs/pages/login/src/lib/hooks/use-redirect-if-logged/use-redirect-if-logged.tsx b/libs/pages/login/src/lib/hooks/use-redirect-if-logged/use-redirect-if-logged.tsx index 533f307bd4..bad6e4be4e 100644 --- a/libs/pages/login/src/lib/hooks/use-redirect-if-logged/use-redirect-if-logged.tsx +++ b/libs/pages/login/src/lib/hooks/use-redirect-if-logged/use-redirect-if-logged.tsx @@ -1,11 +1,18 @@ import { Organization, Project } from 'qovery-typescript-axios' import { useEffect } from 'react' -import { useDispatch } from 'react-redux' +import { useDispatch, useSelector } from 'react-redux' import { useNavigate } from 'react-router-dom' import { fetchOrganization } from '@qovery/domains/organization' import { fetchProjects } from '@qovery/domains/projects' +import { selectUserSignUp } from '@qovery/domains/user' import { useAuth } from '@qovery/shared/auth' -import { ORGANIZATION_URL, OVERVIEW_URL } from '@qovery/shared/router' +import { + ONBOARDING_PERSONALIZE_URL, + ONBOARDING_PROJECT_URL, + ONBOARDING_URL, + ORGANIZATION_URL, + OVERVIEW_URL, +} from '@qovery/shared/router' import { AppDispatch } from '@qovery/store' import { getCurrentOrganizationIdFromStorage, @@ -17,6 +24,7 @@ export function useRedirectIfLogged() { const navigate = useNavigate() const { createAuthCookies, checkIsAuthenticated } = useAuth() const dispatch = useDispatch() + const userSignUp = useSelector(selectUserSignUp) useEffect(() => { async function fetchData() { @@ -35,8 +43,15 @@ export function useRedirectIfLogged() { const projects: Project[] = await dispatch(fetchProjects({ organizationId })).unwrap() if (projects.length > 0) navigate(OVERVIEW_URL(organizationId, projects[0].id)) else navigate(ORGANIZATION_URL(organizationId)) + } else { + if (userSignUp.dx_auth) { + navigate(ONBOARDING_URL + ONBOARDING_PROJECT_URL) + } else { + navigate(ONBOARDING_URL + ONBOARDING_PERSONALIZE_URL) + } } } + if (checkIsAuthenticated) { const currentOrganization = getCurrentOrganizationIdFromStorage() const currentProject = getCurrentProjectIdFromStorage() @@ -55,7 +70,7 @@ export function useRedirectIfLogged() { fetchData() } - }, [navigate, checkIsAuthenticated, createAuthCookies, dispatch]) + }, [navigate, checkIsAuthenticated, createAuthCookies, dispatch, userSignUp.dx_auth]) } export default useRedirectIfLogged