2024-07-27 02:54:23 +05:30
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import { Switch, Route, useLocation, useHistory } from 'react-router-dom';
|
2021-09-02 19:05:13 -07:00
|
|
|
import { Layout } from 'antd';
|
2025-01-29 20:42:01 -05:00
|
|
|
import styled from 'styled-components';
|
2021-09-02 19:05:13 -07:00
|
|
|
import { HomePage } from './home/HomePage';
|
2025-01-29 20:42:01 -05:00
|
|
|
import { HomePage as HomePageV2 } from './homeV2/HomePage';
|
2022-07-01 18:08:08 -04:00
|
|
|
import { SearchRoutes } from './SearchRoutes';
|
2024-01-17 18:15:36 -05:00
|
|
|
import EmbedRoutes from './EmbedRoutes';
|
2024-07-27 02:54:23 +05:30
|
|
|
import { NEW_ROUTE_MAP, PageRoutes } from '../conf/Global';
|
2025-01-29 20:42:01 -05:00
|
|
|
import { useIsThemeV2, useSetThemeIsV2 } from './useIsThemeV2';
|
2024-07-27 02:54:23 +05:30
|
|
|
import { getRedirectUrl } from '../conf/utils';
|
2025-01-29 20:42:01 -05:00
|
|
|
import { IntroduceYourself } from './homeV2/introduce/IntroduceYourself';
|
|
|
|
import { useSetUserTitle } from './identity/user/useUserTitle';
|
|
|
|
import { useSetUserPersona } from './homeV2/persona/useUserPersona';
|
|
|
|
import { useSetNavBarRedesignEnabled } from './useShowNavBarRedesign';
|
|
|
|
import { OnboardingContextProvider } from './onboarding/OnboardingContextProvider';
|
|
|
|
|
|
|
|
const StyledLayout = styled(Layout)`
|
|
|
|
background-color: transparent;
|
|
|
|
`;
|
2021-09-02 19:05:13 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Container for all views behind an authentication wall.
|
|
|
|
*/
|
|
|
|
export const ProtectedRoutes = (): JSX.Element => {
|
2025-01-29 20:42:01 -05:00
|
|
|
useSetThemeIsV2();
|
|
|
|
useSetUserPersona();
|
|
|
|
useSetUserTitle();
|
|
|
|
useSetNavBarRedesignEnabled();
|
|
|
|
|
|
|
|
const isThemeV2 = useIsThemeV2();
|
|
|
|
const FinalHomePage = isThemeV2 ? HomePageV2 : HomePage;
|
|
|
|
|
2024-07-27 02:54:23 +05:30
|
|
|
const location = useLocation();
|
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (location.pathname.indexOf('/Validation') !== -1) {
|
|
|
|
history.replace(getRedirectUrl(NEW_ROUTE_MAP));
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [location]);
|
|
|
|
|
2021-09-02 19:05:13 -07:00
|
|
|
return (
|
2025-01-29 20:42:01 -05:00
|
|
|
<OnboardingContextProvider>
|
|
|
|
<StyledLayout className={isThemeV2 ? 'themeV2' : undefined}>
|
|
|
|
<Switch>
|
|
|
|
<Route exact path="/" render={() => <FinalHomePage />} />
|
|
|
|
<Route path={PageRoutes.EMBED} render={() => <EmbedRoutes />} />
|
|
|
|
<Route exact path={PageRoutes.INTRODUCE} render={() => <IntroduceYourself />} />
|
|
|
|
<Route path="/*" render={() => <SearchRoutes />} />
|
|
|
|
</Switch>
|
|
|
|
</StyledLayout>
|
|
|
|
</OnboardingContextProvider>
|
2021-09-02 19:05:13 -07:00
|
|
|
);
|
|
|
|
};
|