appFactory.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React from 'react'
  2. import { FETCH_CONFIG } from './helper.js'
  3. export function appFactory (WrappedComponent) {
  4. return class AppFactory extends React.Component {
  5. renderAppFull = (appConfig, user, content) => GLOBAL_renderAppFull({
  6. loggedUser: user.logged ? user : {},
  7. config: {
  8. ...appConfig,
  9. domContainer: 'appContainer',
  10. apiUrl: FETCH_CONFIG.apiUrl,
  11. mockApiUrl: FETCH_CONFIG.mockApiUrl,
  12. apiHeader: FETCH_CONFIG.headers
  13. },
  14. content
  15. })
  16. renderAppPopupCreation = (appConfig, user, idWorkspace, idFolder) => GLOBAL_renderAppPopupCreation({
  17. loggedUser: user.logged ? user : {},
  18. config: {
  19. ...appConfig,
  20. domContainer: 'popupCreateContentContainer',
  21. apiUrl: FETCH_CONFIG.apiUrl,
  22. mockApiUrl: FETCH_CONFIG.mockApiUrl,
  23. apiHeader: FETCH_CONFIG.headers // should this be used by app ? right now, apps have their own headers
  24. },
  25. idWorkspace,
  26. idFolder: idFolder === 'null' ? null : idFolder
  27. })
  28. emitEventApp = (type, data) => GLOBAL_dispatchEvent({ type, data })
  29. render () {
  30. return (
  31. <WrappedComponent
  32. {...this.props}
  33. renderAppFull={this.renderAppFull}
  34. renderAppPopupCreation={this.renderAppPopupCreation}
  35. emitEventApp={this.emitEventApp}
  36. // hideApp={this.hideApp}
  37. />
  38. )
  39. }
  40. }
  41. }
  42. export default appFactory