appFactory.js 2.1KB

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