OpenCreateContentApp.jsx 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. export class OpenCreateContentApp extends React.Component {
  7. openCreateContentApp = () => {
  8. const { idWorkspace, user, contentType, renderAppPopupCreation, match, location } = this.props
  9. if (isNaN(idWorkspace) || idWorkspace === -1) return
  10. if (['idws', 'type'].every(p => p in match.params) && contentType.map(c => c.slug).includes(match.params.type)) {
  11. renderAppPopupCreation(
  12. contentType.find(ct => ct.slug === match.params.type),
  13. user,
  14. idWorkspace,
  15. qs.parse(location.search).parent_id
  16. )
  17. }
  18. }
  19. componentDidMount () {
  20. console.log('%c<OpenCreateContentApp> did Mount', 'color: #dcae84', this.props)
  21. this.openCreateContentApp()
  22. }
  23. componentDidUpdate () {
  24. console.log('%c<OpenCreateContentApp> did Update', 'color: #dcae84', this.props)
  25. this.openCreateContentApp()
  26. }
  27. render () {
  28. return null
  29. }
  30. }
  31. const mapStateToProps = ({ user, workspaceContent, contentType }) => ({ user, workspaceContent, contentType })
  32. export default withRouter(connect(mapStateToProps)(appFactory(OpenCreateContentApp)))