Tracim.jsx 1.5KB

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