Tracim.jsx 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 { getIsUserConnected } from '../action-creator.async.js'
  18. class Tracim extends React.Component {
  19. componentDidMount = () => {
  20. this.props.dispatch(getIsUserConnected())
  21. }
  22. render () {
  23. const { user, location } = this.props
  24. const SidebarWrapper = props => props.locationPath !== '/login'
  25. ? (
  26. <div className='sidebarpagecontainer'>
  27. <Sidebar />
  28. {props.children}
  29. </div>
  30. )
  31. : props.children
  32. return (
  33. <div>
  34. <Header />
  35. { user.isLoggedIn === undefined
  36. ? (<div />) // while we dont know if user is connected, display nothing but the header @TODO show loader
  37. : (
  38. <div>
  39. <Route path={PAGE_NAME.LOGIN} component={Login} />
  40. <SidebarWrapper locationPath={location.pathname}>
  41. <PrivateRoute exact path={PAGE_NAME.HOME} component={WorkspaceContent} />
  42. <PrivateRoute path={`${PAGE_NAME.WS_CONTENT}/:idws`} component={WorkspaceContent} />
  43. <PrivateRoute exact path={PAGE_NAME.ACCOUNT} component={AccountPage} />
  44. <PrivateRoute exact path={PAGE_NAME.DASHBOARD} component={Dashboard} />
  45. </SidebarWrapper>
  46. <Footer />
  47. </div>
  48. )
  49. }
  50. </div>
  51. )
  52. }
  53. }
  54. const mapStateToProps = ({ user }) => ({ user })
  55. export default withRouter(connect(mapStateToProps)(Tracim))