-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroot.js
More file actions
55 lines (49 loc) · 1.61 KB
/
root.js
File metadata and controls
55 lines (49 loc) · 1.61 KB
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
import React from 'react'
import { Route, Switch } from 'react-router-dom'
import { connect } from 'react-redux'
import { toast } from 'react-toastify'
import * as am4core from '@amcharts/amcharts4/core'
import * as am4charts from '@amcharts/amcharts4/charts'
import am4themes_animated from '@amcharts/amcharts4/themes/animated'
import { LoadingAnimation as Loading } from '@components'
import AppActions from '~/actions/app'
import indexRoutes from '~/routes'
import { loading, version } from '~/services/util'
am4core.useTheme(am4themes_animated)
const ROOT = props => {
if (props.version !== '1.0.0' && props.version !== version()) {
toast.success(
`We've released new features.
Login for the free upgrade!`,
{
position: toast.POSITION.TOP_RIGHT,
}
)
props.logout()
}
return (
<>
<Switch>
{indexRoutes.map((prop, key) => {
if (prop.name === 'Home') {
return <Route to={prop.path} component={prop.component} key={key} />
} else return <Route exact path={prop.path} component={prop.component} key={key} />
})}
</Switch>
<Loading loading={props.busy} onReset={() => props.logout()} />
</>
)
}
const mapStateToProps = state => ({
busy:
loading(state.app.status) ||
loading(state.develop.status) ||
loading(state.manage.status) ||
loading(state.community.status) ||
loading(state.vendor.status),
version: state.app.version,
})
const mapDispatchToProps = dispatch => ({
logout: () => dispatch(AppActions.logoutRequest()),
})
export default connect(mapStateToProps, mapDispatchToProps)(ROOT)