installer.jsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import { I18nextProvider } from 'react-i18next';
  4. import { SWRConfig } from 'swr';
  5. import { swrGlobalConfiguration } from '~/utils/swr-utils';
  6. import InstallerForm from '../components/InstallerForm';
  7. import ContextExtractor from './services/ContextExtractor';
  8. import { i18nFactory } from './util/i18n';
  9. const i18n = i18nFactory();
  10. const componentMappings = {};
  11. // render InstallerForm
  12. const installerFormContainerElem = document.getElementById('installer-form-container');
  13. if (installerFormContainerElem) {
  14. const userName = installerFormContainerElem.dataset.userName;
  15. const name = installerFormContainerElem.dataset.name;
  16. const email = installerFormContainerElem.dataset.email;
  17. Object.assign(componentMappings, {
  18. 'installer-form-container': <InstallerForm userName={userName} name={name} email={email} />,
  19. });
  20. }
  21. const renderMainComponents = () => {
  22. Object.keys(componentMappings).forEach((key) => {
  23. const elem = document.getElementById(key);
  24. if (elem) {
  25. ReactDOM.render(
  26. <I18nextProvider i18n={i18n}>
  27. <SWRConfig value={swrGlobalConfiguration}>
  28. {componentMappings[key]}
  29. </SWRConfig>
  30. </I18nextProvider>,
  31. elem,
  32. );
  33. }
  34. });
  35. };
  36. // extract context before rendering main components
  37. const elem = document.getElementById('growi-context-extractor');
  38. if (elem != null) {
  39. ReactDOM.render(
  40. <SWRConfig value={swrGlobalConfiguration}>
  41. <ContextExtractor></ContextExtractor>
  42. </SWRConfig>,
  43. elem,
  44. renderMainComponents,
  45. );
  46. }
  47. else {
  48. renderMainComponents();
  49. }