2021-10-11 16:21:15 +05:30
|
|
|
import ROUTES from 'constants/routes';
|
2021-10-20 09:24:55 +05:30
|
|
|
import TopNav from 'container/Header';
|
|
|
|
|
import SideNav from 'container/SideNav';
|
2021-10-11 16:21:15 +05:30
|
|
|
import history from 'lib/history';
|
2021-10-22 17:05:10 +05:30
|
|
|
import React, { ReactNode, useEffect, useState } from 'react';
|
2021-10-11 16:21:15 +05:30
|
|
|
import { useSelector } from 'react-redux';
|
2022-03-24 12:06:57 +05:30
|
|
|
import { useLocation } from 'react-router-dom';
|
2021-10-11 16:21:15 +05:30
|
|
|
import { AppState } from 'store/reducers';
|
|
|
|
|
import AppReducer from 'types/reducer/app';
|
2021-05-16 18:35:50 +05:30
|
|
|
|
2022-03-14 20:12:42 +05:30
|
|
|
import { Content, Layout } from './styles';
|
2021-05-16 18:35:50 +05:30
|
|
|
|
2022-03-24 12:06:57 +05:30
|
|
|
function AppLayout(props: AppLayoutProps): JSX.Element {
|
2021-10-11 16:21:15 +05:30
|
|
|
const { isLoggedIn } = useSelector<AppState, AppReducer>((state) => state.app);
|
2022-03-24 12:06:57 +05:30
|
|
|
const { pathname } = useLocation();
|
2021-05-23 14:15:13 +05:30
|
|
|
|
2022-03-24 12:06:57 +05:30
|
|
|
const [isSignUpPage, setIsSignUpPage] = useState(ROUTES.SIGN_UP === pathname);
|
|
|
|
|
|
|
|
|
|
const { children } = props;
|
2021-05-23 14:15:13 +05:30
|
|
|
|
2021-10-22 17:05:10 +05:30
|
|
|
useEffect(() => {
|
|
|
|
|
if (!isLoggedIn) {
|
|
|
|
|
setIsSignUpPage(true);
|
|
|
|
|
history.push(ROUTES.SIGN_UP);
|
2022-03-22 12:10:31 +05:30
|
|
|
} else if (isSignUpPage) {
|
|
|
|
|
setIsSignUpPage(false);
|
2021-10-11 16:21:15 +05:30
|
|
|
}
|
2021-10-22 17:05:10 +05:30
|
|
|
}, [isLoggedIn, isSignUpPage]);
|
2021-10-20 09:24:55 +05:30
|
|
|
|
2022-04-01 15:47:39 +05:30
|
|
|
useEffect(() => {
|
2022-04-04 10:25:15 +05:30
|
|
|
if (isLoggedIn && pathname === ROUTES.SIGN_UP) {
|
2022-04-01 15:47:39 +05:30
|
|
|
history.push(ROUTES.APPLICATION);
|
|
|
|
|
}
|
2022-04-04 10:25:15 +05:30
|
|
|
}, [isLoggedIn, pathname]);
|
2022-04-01 15:47:39 +05:30
|
|
|
|
2021-05-16 18:35:50 +05:30
|
|
|
return (
|
2021-12-02 20:12:38 +05:30
|
|
|
<Layout>
|
2021-10-22 17:05:10 +05:30
|
|
|
{!isSignUpPage && <SideNav />}
|
2021-12-02 20:12:38 +05:30
|
|
|
<Layout>
|
|
|
|
|
<Content>
|
2021-10-22 17:05:10 +05:30
|
|
|
{!isSignUpPage && <TopNav />}
|
2021-05-16 18:35:50 +05:30
|
|
|
{children}
|
|
|
|
|
</Content>
|
|
|
|
|
</Layout>
|
|
|
|
|
</Layout>
|
|
|
|
|
);
|
2022-03-24 12:06:57 +05:30
|
|
|
}
|
2021-05-16 18:35:50 +05:30
|
|
|
|
2021-10-22 17:05:10 +05:30
|
|
|
interface AppLayoutProps {
|
|
|
|
|
children: ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default AppLayout;
|