|
@@ -1,18 +1,17 @@
|
1
|
1
|
import React from 'react'
|
2
|
2
|
import { connect } from 'react-redux'
|
3
|
3
|
import { translate } from 'react-i18next'
|
|
4
|
+import Sidebar from './Sidebar.jsx'
|
4
|
5
|
import Header from './Header.jsx'
|
5
|
6
|
import Login from './Login.jsx'
|
6
|
|
-import Dashboard from './Dashboard.jsx'
|
7
|
7
|
import Account from './Account.jsx'
|
8
|
8
|
import AppFullscreenManager from './AppFullscreenManager.jsx'
|
9
|
9
|
import FlashMessage from '../component/FlashMessage.jsx'
|
10
|
10
|
import WorkspaceContent from './WorkspaceContent.jsx'
|
11
|
11
|
import WIPcomponent from './WIPcomponent.jsx'
|
12
|
12
|
import {
|
13
|
|
- Route, withRouter, Switch
|
|
13
|
+ Route, withRouter, Redirect
|
14
|
14
|
} from 'react-router-dom'
|
15
|
|
-import PrivateRoute from './PrivateRoute.jsx'
|
16
|
15
|
import { COOKIE, PAGE } from '../helper.js'
|
17
|
16
|
import {
|
18
|
17
|
getUserIsConnected
|
|
@@ -22,6 +21,7 @@ import {
|
22
|
21
|
setUserConnected
|
23
|
22
|
} from '../action-creator.sync.js'
|
24
|
23
|
import Cookies from 'js-cookie'
|
|
24
|
+import Dashboard from './Dashboard.jsx'
|
25
|
25
|
|
26
|
26
|
class Tracim extends React.Component {
|
27
|
27
|
constructor (props) {
|
|
@@ -40,6 +40,7 @@ class Tracim extends React.Component {
|
40
|
40
|
}
|
41
|
41
|
|
42
|
42
|
async componentDidMount () {
|
|
43
|
+ // console.log('<Tracim> did Mount')
|
43
|
44
|
const { dispatch } = this.props
|
44
|
45
|
|
45
|
46
|
const userFromCookies = {
|
|
@@ -66,27 +67,57 @@ class Tracim extends React.Component {
|
66
|
67
|
handleRemoveFlashMessage = msg => this.props.dispatch(removeFlashMessage(msg))
|
67
|
68
|
|
68
|
69
|
render () {
|
69
|
|
- const { flashMessage, t } = this.props
|
|
70
|
+ const { props } = this
|
70
|
71
|
|
71
|
72
|
return (
|
72
|
73
|
<div className='tracim'>
|
73
|
74
|
<Header />
|
74
|
|
- <FlashMessage flashMessage={flashMessage} removeFlashMessage={this.handleRemoveFlashMessage} t={t} />
|
|
75
|
+ <FlashMessage flashMessage={props.flashMessage} removeFlashMessage={this.handleRemoveFlashMessage} t={props.t} />
|
75
|
76
|
|
76
|
77
|
<div className='tracim__content'>
|
77
|
78
|
<Route path={PAGE.LOGIN} component={Login} />
|
78
|
79
|
|
79
|
|
- <PrivateRoute exact path='/' component={WorkspaceContent} />
|
80
|
|
-
|
81
|
|
- <Switch>
|
82
|
|
- <PrivateRoute path={PAGE.WORKSPACE.DASHBOARD(':idws')} component={Dashboard} />
|
83
|
|
- <PrivateRoute path={PAGE.WORKSPACE.CALENDAR(':idws')} component={() => <div><br /><br /><br /><br />NYI</div>} />
|
84
|
|
- <PrivateRoute path={PAGE.WORKSPACE.CONTENT(':idws', ':type?', ':idcts?')} component={WorkspaceContent} />
|
85
|
|
- </Switch>
|
86
|
|
-
|
87
|
|
- <PrivateRoute path={PAGE.ACCOUNT} component={Account} />
|
88
|
|
- <PrivateRoute path={PAGE.ADMIN.ROOT} component={AppFullscreenManager} />
|
89
|
|
- <PrivateRoute path={'/wip/:cp'} component={WIPcomponent} /> {/* for testing purpose only */}
|
|
80
|
+ <Route exact path='/' component={() => {
|
|
81
|
+ switch (props.user.logged) {
|
|
82
|
+ case true:
|
|
83
|
+ return <Redirect to={{pathname: PAGE.WORKSPACE.ROOT, state: {from: props.location}}} />
|
|
84
|
+ case false:
|
|
85
|
+ return <Redirect to={{pathname: '/login', state: {from: props.location}}} />
|
|
86
|
+ case null:
|
|
87
|
+ return null
|
|
88
|
+ }
|
|
89
|
+ }} />
|
|
90
|
+
|
|
91
|
+ { props.user.logged
|
|
92
|
+ ? (
|
|
93
|
+ <Route path='/workspaces/:idws?' render={() => // Workspace Router
|
|
94
|
+ <div className='sidebarpagecontainer'>
|
|
95
|
+ <Sidebar />
|
|
96
|
+
|
|
97
|
+ <Route exact path={PAGE.WORKSPACE.ROOT} render={() => props.workspaceList.length === 0 // handle '/' and redirect to first workspace
|
|
98
|
+ ? null
|
|
99
|
+ : <Redirect to={{pathname: `/workspaces/${props.workspaceList[0].id}/contents`, state: {from: props.location}}} />
|
|
100
|
+ } />
|
|
101
|
+
|
|
102
|
+ <Route exact path={`${PAGE.WORKSPACE.ROOT}/:idws`} render={props2 => // handle '/workspaces/:id' and add '/contents'
|
|
103
|
+ <Redirect to={{pathname: `/workspaces/${props2.match.params.idws}/contents`, state: {from: props.location}}} />
|
|
104
|
+ } />
|
|
105
|
+
|
|
106
|
+ <Route path={PAGE.WORKSPACE.DASHBOARD(':idws')} component={Dashboard} />
|
|
107
|
+ <Route path={PAGE.WORKSPACE.CALENDAR(':idws')} component={() => <div><br /><br /><br /><br />NYI</div>} />
|
|
108
|
+ <Route path={PAGE.WORKSPACE.CONTENT(':idws', ':type', ':idcts')} component={WorkspaceContent} />
|
|
109
|
+ <Route exact path={PAGE.WORKSPACE.CONTENT_LIST(':idws')} component={WorkspaceContent} />
|
|
110
|
+
|
|
111
|
+ <Route path={PAGE.ACCOUNT} component={Account} />
|
|
112
|
+ <Route path={PAGE.ADMIN.ROOT} component={AppFullscreenManager} />
|
|
113
|
+ </div>
|
|
114
|
+ } />
|
|
115
|
+ )
|
|
116
|
+ : props.user.logged === false && props.location.pathname !== '/login' &&
|
|
117
|
+ <Redirect to={{pathname: '/login', state: {from: props.location}}} />
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ <Route path={'/wip/:cp'} component={WIPcomponent} /> {/* for testing purpose only */}
|
90
|
121
|
|
91
|
122
|
<div id='appFeatureContainer' />
|
92
|
123
|
</div>
|
|
@@ -96,5 +127,5 @@ class Tracim extends React.Component {
|
96
|
127
|
}
|
97
|
128
|
}
|
98
|
129
|
|
99
|
|
-const mapStateToProps = ({ user, appList, contentType, flashMessage }) => ({ user, appList, contentType, flashMessage })
|
|
130
|
+const mapStateToProps = ({ user, appList, contentType, workspaceList, flashMessage }) => ({ user, appList, contentType, workspaceList, flashMessage })
|
100
|
131
|
export default withRouter(connect(mapStateToProps)(translate()(Tracim)))
|