From 73e3e061e037bb8a52f9ac9dece9ac75f9420e4b Mon Sep 17 00:00:00 2001 From: pal-sig <88981777+pal-sig@users.noreply.github.com> Date: Fri, 22 Oct 2021 17:05:10 +0530 Subject: [PATCH] feat: signup logic is now fixed (#349) --- frontend/src/container/AppLayout/index.tsx | 38 +++++++++---------- frontend/src/pages/SignUp/index.tsx | 11 +++--- frontend/src/store/actions/app/index.ts | 1 + .../src/store/actions/app/userLoggedIn.ts | 13 +++++++ frontend/src/store/reducers/app.ts | 9 ++++- frontend/src/types/actions/app.ts | 7 +++- 6 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 frontend/src/store/actions/app/userLoggedIn.ts diff --git a/frontend/src/container/AppLayout/index.tsx b/frontend/src/container/AppLayout/index.tsx index 66cc5f1fc4..f0df30aaa7 100644 --- a/frontend/src/container/AppLayout/index.tsx +++ b/frontend/src/container/AppLayout/index.tsx @@ -1,45 +1,41 @@ import { Layout } from 'antd'; -import get from 'api/browser/localstorage/get'; import ROUTES from 'constants/routes'; import TopNav from 'container/Header'; import SideNav from 'container/SideNav'; import history from 'lib/history'; -import React, { ReactNode, useEffect } from 'react'; +import React, { ReactNode, useEffect, useState } from 'react'; import { useSelector } from 'react-redux'; import { AppState } from 'store/reducers'; import AppReducer from 'types/reducer/app'; const { Content, Footer } = Layout; -interface BaseLayoutProps { - children: ReactNode; -} -const BaseLayout: React.FC = ({ children }) => { +const AppLayout: React.FC = ({ children }) => { const { isLoggedIn } = useSelector((state) => state.app); - const isLoggedInLocalStorage = get('isLoggedIn'); + + const [isSignUpPage, setIsSignUpPage] = useState( + ROUTES.SIGN_UP === location.pathname, + ); useEffect(() => { - if (isLoggedIn && history.location.pathname === '/') { - history.push(ROUTES.APPLICATION); - } - - if (!isLoggedIn && isLoggedInLocalStorage !== null) { - history.push(ROUTES.APPLICATION); + if (!isLoggedIn) { + setIsSignUpPage(true); + history.push(ROUTES.SIGN_UP); } else { - if (isLoggedInLocalStorage === null) { - history.push(ROUTES.SIGN_UP); + if (isSignUpPage) { + setIsSignUpPage(false); } } - }, [isLoggedIn, isLoggedInLocalStorage]); + }, [isLoggedIn, isSignUpPage]); const currentYear = new Date().getFullYear(); return ( - + {!isSignUpPage && } - + {!isSignUpPage && } {children}