Tracim.jsx 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import Footer from '../component/Footer.jsx'
  4. import Header from './Header.jsx'
  5. import Sidebar from './Sidebar.jsx'
  6. import Login from './Login.jsx'
  7. import Dashboard from './Dashboard.jsx'
  8. import AccountPage from './AccountPage.jsx'
  9. // import FlashMessage from './FlashMessage.jsx'
  10. import WorkspaceContent from './WorkspaceContent.jsx'
  11. import {
  12. Route,
  13. withRouter
  14. } from 'react-router-dom'
  15. import PrivateRoute from './PrivateRoute.jsx'
  16. import { PAGE_NAME } from '../helper.js'
  17. import {
  18. getLangList,
  19. getIsUserConnected
  20. } from '../action-creator.async.js'
  21. class Tracim extends React.Component {
  22. componentDidMount = () => {
  23. this.props.dispatch(getIsUserConnected())
  24. this.props.dispatch(getLangList())
  25. }
  26. render () {
  27. const { user, location } = this.props
  28. const SidebarWrapper = props => props.locationPath !== '/login'
  29. ? (
  30. <div className='sidebarpagecontainer'>
  31. <Sidebar />
  32. {props.children}
  33. </div>
  34. )
  35. : props.children
  36. return (
  37. <div>
  38. <Header />
  39. { user.isLoggedIn === undefined
  40. ? (<div />) // while we dont know if user is connected, display nothing but the header @TODO show loader
  41. : (
  42. <div>
  43. <Route path={PAGE_NAME.LOGIN} component={Login} />
  44. <SidebarWrapper locationPath={location.pathname}>
  45. <PrivateRoute exact path={PAGE_NAME.HOME} component={WorkspaceContent} />
  46. <PrivateRoute path={`${PAGE_NAME.WS_CONTENT}/:idws`} component={WorkspaceContent} />
  47. <PrivateRoute exact path={PAGE_NAME.ACCOUNT} component={AccountPage} />
  48. <PrivateRoute exact path={PAGE_NAME.DASHBOARD} component={Dashboard} />
  49. </SidebarWrapper>
  50. <Footer />
  51. </div>
  52. )
  53. }
  54. </div>
  55. )
  56. }
  57. }
  58. const mapStateToProps = ({ user }) => ({ user })
  59. export default withRouter(connect(mapStateToProps)(Tracim))