-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
74 lines (59 loc) · 1.87 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React, { useEffect, Suspense } from 'react';
import { Route, Switch, withRouter, Redirect } from 'react-router-dom';
import Layout from './hoc/Layout/Layout';
import BurgerBuilder from './containers/BurgerBuilder/BurgerBuilder';
import Logout from '../src/containers/Auth/Logout/Logout';
import {connect} from 'react-redux';
import * as actions from '../src/store/actions/index';
//import asyncComponent from './hoc/asyncComponent/asyncComponent';
const Checkout = React.lazy(()=> {
return import('./containers/Checkout/Checkout');
});
const Orders = React.lazy(()=> {
return import('./containers/Orders/Orders');
});
const Auth = React.lazy(()=> {
return import('../src/containers/Auth/Auth');
});
const app = (props) => {
useEffect( ()=> {
props.onTryAutoSignUp();
}, [] );
let routes = (
<Switch>
<Route path="/" exact component={BurgerBuilder} />
<Route path="/auth" render={ (props)=><Auth {...props} />} />
<Redirect to='/' />
</Switch>
);
if(props.isAuthenticated) {
routes= (
<Switch>
<Route path="/" exact component={BurgerBuilder} />
<Route path="/checkout"render={ (props)=><Checkout {...props} />} />
<Route path="/orders" render={ (props)=><Orders {...props} />} />
<Route path="/logout" component={Logout} />
<Route path="/auth" render={ (props)=><Auth {...props} />} />
<Redirect to='/' />
</Switch>
);
}
return (
<div>
<Layout>
<Suspense fallback={<p>Loading...</p>}>{routes}</Suspense>
</Layout>
</div>
);
}
const mapStateToProps= state => {
return {
isAuthenticated : state.auth.token !== null
}
}
const mapDispatchToProps = dispatch => {
return {
onTryAutoSignUp: () => dispatch(actions.authCheckState())
}
}
export default withRouter(connect(mapStateToProps,mapDispatchToProps) (app));