Tracim.jsx 1.8KB

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