OpenCreateContentApp.jsx 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import { withRouter } from 'react-router'
  4. import appFactory from '../../appFactory.js'
  5. const qs = require('query-string')
  6. // @FIXME Côme - 2018/07/31 - should this be in a component like AppFeatureManager ? (or AppCreateContentManager)
  7. export class OpenCreateContentApp extends React.Component {
  8. openCreateContentApp = () => {
  9. const { idWorkspace, user, contentType, renderAppPopupCreation, match, location } = this.props
  10. if (isNaN(idWorkspace) || idWorkspace === -1) return
  11. if (['idws', 'type'].every(p => p in match.params) && contentType.map(c => c.slug).includes(match.params.type)) {
  12. renderAppPopupCreation(
  13. contentType.find(ct => ct.slug === match.params.type),
  14. user,
  15. idWorkspace,
  16. qs.parse(location.search).parent_id
  17. )
  18. }
  19. }
  20. componentDidMount () {
  21. console.log('%c<OpenCreateContentApp> did Mount', 'color: #dcae84', this.props)
  22. this.openCreateContentApp()
  23. }
  24. componentDidUpdate () {
  25. console.log('%c<OpenCreateContentApp> did Update', 'color: #dcae84', this.props)
  26. this.openCreateContentApp()
  27. }
  28. render () {
  29. return null
  30. }
  31. }
  32. const mapStateToProps = ({ user, workspaceContent, contentType }) => ({ user, workspaceContent, contentType })
  33. export default withRouter(connect(mapStateToProps)(appFactory(OpenCreateContentApp)))