AppFullscreenRouter.jsx 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import { withRouter } from 'react-router'
  4. import { Route, Redirect } from 'react-router-dom'
  5. import { PAGE, PROFILE } from '../helper.js'
  6. import appFactory from '../appFactory.js'
  7. class AppFullscreenRouter extends React.Component {
  8. constructor (props) {
  9. super(props)
  10. this.state = {
  11. isMounted: false
  12. }
  13. }
  14. componentDidMount = () => this.setState({isMounted: true})
  15. render () {
  16. const { props } = this
  17. return (
  18. <div className='AppFullScreenManager'>
  19. <div id='appFullscreenContainer' />
  20. {this.state.isMounted && (// we must wait for the component to be fully mounted to be sure the div#appFullscreenContainer exists in DOM
  21. <div className='emptyDivForRoute'>
  22. <Route path={PAGE.ADMIN.WORKSPACE} render={() => {
  23. if (props.user.profile !== PROFILE.ADMINISTRATOR.slug) return <Redirect to={{pathname: '/'}} />
  24. const content = {
  25. workspaceList: [],
  26. userList: []
  27. }
  28. props.renderAppFullscreen({slug: 'admin_workspace_user', hexcolor: '#7d4e24', type: 'workspace'}, props.user, content)
  29. return null
  30. }} />
  31. <Route path={PAGE.ADMIN.USER} render={() => {
  32. if (props.user.profile !== PROFILE.ADMINISTRATOR.slug) return <Redirect to={{pathname: '/'}} />
  33. const content = {
  34. profile: PROFILE,
  35. workspaceList: [],
  36. userList: []
  37. }
  38. props.renderAppFullscreen({slug: 'admin_workspace_user', hexcolor: '#7d4e24', type: 'user'}, props.user, content)
  39. return null
  40. }} />
  41. </div>
  42. )}
  43. </div>
  44. )
  45. }
  46. }
  47. const mapStateToProps = ({ user }) => ({ user })
  48. export default withRouter(connect(mapStateToProps)(appFactory(AppFullscreenRouter)))