source: sources/client/src/screens/UserAndNotAuthScreen/index.js

Last change on this file was bc20307, checked in by Tasevski2 <39170279+Tasevski2@…>, 2 years ago

Push before video

  • Property mode set to 100644
File size: 3.2 KB
Line 
1import { useContext, useState } from 'react';
2import { Switch, Route, Redirect, useLocation } from 'react-router-dom';
3import HeaderUserAndAuth from '../../components/HeaderUserAndAuth';
4import { AccessoriesContext } from '../../context/AccessoriesContext';
5import { Wrapper, ScreenWrapper } from './styles';
6import { UserContext } from '../../context/UserContext';
7import { roles } from '../../config/enums';
8
9import Landing from '../../components/user/Landing'; // USER
10import MyProfile from '../../components/user/MyProfile';
11// MapUsers - same as guest and auth but diffrent url USER
12import Session from '../../components/user/Session'; // USER and GUEST
13import Auth from '../../components/Auth'; // NOT AUTH
14import MapUsers from '../../components/user/MapUsers'; // TODO GUEST and NOT AUTH
15
16import { DndProvider } from 'react-dnd';
17import { TouchBackend } from 'react-dnd-touch-backend';
18
19const UserAndNotAuthScreen = () => {
20 const { user } = useContext(UserContext);
21 const location = useLocation();
22 const { isMobile } = useContext(AccessoriesContext);
23 const [isUserParked, setIsUserParked] = useState(false); // TODO FETCH
24 const asphaltBg =
25 user && user.role === roles.user && location.pathname === '/';
26 const mapUrl = user && user.role === roles.user ? '/maps' : '/';
27 const options = {
28 enableMouseEvents: true,
29 };
30 const content = (
31 <Wrapper asphaltBg={asphaltBg}>
32 <DndProvider backend={TouchBackend} options={options}>
33 <HeaderUserAndAuth />
34 <Switch>
35 {!user ? ( // NOT AUTH ROUTES
36 <Auth />
37 ) : (
38 <>
39 {user.role === roles.user ? ( // USER ROUTES
40 <>
41 <Route
42 exact
43 path={'/'}
44 component={() => (
45 <Landing
46 isParked={isUserParked}
47 setIsParked={setIsUserParked}
48 />
49 )}
50 />
51
52 <Route
53 exact
54 path={'/my-profile'}
55 component={MyProfile}
56 />
57 </>
58 ) : null}
59 {/* USER AND GUEST ROUTES */}
60 <Route exact path='/session' component={Session} />
61 <Route exact path={mapUrl} component={MapUsers} />
62 <Redirect to='/' />
63 </>
64 )}
65 {/* USER, GUEST AND NOT AUTH ROUTES */}
66 <Redirect to='/' />
67 </Switch>
68 </DndProvider>
69 </Wrapper>
70 );
71
72 return isMobile ? content : <ScreenWrapper>{content}</ScreenWrapper>;
73};
74
75export default UserAndNotAuthScreen;
Note: See TracBrowser for help on using the repository browser.