appFactory.js 1.5KB

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