appFactory.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React from 'react'
  2. import { FETCH_CONFIG } from './helper.js'
  3. import i18n from './i18n.js'
  4. export function appFactory (WrappedComponent) {
  5. return class AppFactory extends React.Component {
  6. renderAppFeature = (appConfig, user, content) => GLOBAL_renderAppFeature({
  7. loggedUser: user.logged ? user : {},
  8. config: {
  9. ...appConfig,
  10. domContainer: 'appFeatureContainer',
  11. apiUrl: FETCH_CONFIG.apiUrl,
  12. mockApiUrl: FETCH_CONFIG.mockApiUrl, // Côme - 2018/07/31 - this should not be used, I deprecate it
  13. apiHeader: FETCH_CONFIG.headers,
  14. translation: i18n.store.data
  15. },
  16. content
  17. })
  18. renderAppFullscreen = (appConfig, user, content) => GLOBAL_renderAppFullscreen({
  19. loggedUser: user.logged ? user : {},
  20. config: {
  21. ...appConfig,
  22. domContainer: 'appFullscreenContainer',
  23. apiUrl: FETCH_CONFIG.apiUrl,
  24. apiHeader: FETCH_CONFIG.headers,
  25. translation: i18n.store.data
  26. },
  27. content
  28. })
  29. renderAppPopupCreation = (appConfig, user, idWorkspace, idFolder) => GLOBAL_renderAppPopupCreation({
  30. loggedUser: user.logged ? user : {},
  31. config: {
  32. ...appConfig,
  33. domContainer: 'popupCreateContentContainer',
  34. apiUrl: FETCH_CONFIG.apiUrl,
  35. mockApiUrl: FETCH_CONFIG.mockApiUrl,
  36. apiHeader: FETCH_CONFIG.headers, // should this be used by app ? right now, apps have their own headers
  37. translation: i18n.store.data
  38. },
  39. idWorkspace,
  40. idFolder: idFolder === 'null' ? null : idFolder
  41. })
  42. dispatchCustomEvent = (type, data) => GLOBAL_dispatchEvent({ type, data })
  43. render () {
  44. return (
  45. <WrappedComponent
  46. {...this.props}
  47. renderAppFeature={this.renderAppFeature}
  48. renderAppFullscreen={this.renderAppFullscreen}
  49. renderAppPopupCreation={this.renderAppPopupCreation}
  50. dispatchCustomEvent={this.dispatchCustomEvent}
  51. // hideApp={this.hideApp}
  52. />
  53. )
  54. }
  55. }
  56. }
  57. export default appFactory