[bc20307] | 1 | import { useContext, useState } from 'react';
|
---|
| 2 | import { Switch, Route, Redirect, useLocation } from 'react-router-dom';
|
---|
| 3 | import HeaderUserAndAuth from '../../components/HeaderUserAndAuth';
|
---|
| 4 | import { AccessoriesContext } from '../../context/AccessoriesContext';
|
---|
| 5 | import { Wrapper, ScreenWrapper } from './styles';
|
---|
| 6 | import { UserContext } from '../../context/UserContext';
|
---|
| 7 | import { roles } from '../../config/enums';
|
---|
| 8 |
|
---|
| 9 | import Landing from '../../components/user/Landing'; // USER
|
---|
| 10 | import MyProfile from '../../components/user/MyProfile';
|
---|
| 11 | // MapUsers - same as guest and auth but diffrent url USER
|
---|
| 12 | import Session from '../../components/user/Session'; // USER and GUEST
|
---|
| 13 | import Auth from '../../components/Auth'; // NOT AUTH
|
---|
| 14 | import MapUsers from '../../components/user/MapUsers'; // TODO GUEST and NOT AUTH
|
---|
| 15 |
|
---|
| 16 | import { DndProvider } from 'react-dnd';
|
---|
| 17 | import { TouchBackend } from 'react-dnd-touch-backend';
|
---|
| 18 |
|
---|
| 19 | const 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 |
|
---|
| 75 | export default UserAndNotAuthScreen;
|
---|