yusuketk 6 лет назад
Родитель
Сommit
b9b5419f08
2 измененных файлов с 19 добавлено и 8 удалено
  1. 11 1
      src/client/js/components/LoginForm.jsx
  2. 8 7
      src/client/js/nologin.jsx

+ 11 - 1
src/client/js/components/LoginForm.jsx

@@ -3,6 +3,9 @@ import PropTypes from 'prop-types';
 
 import { withTranslation } from 'react-i18next';
 
+import AppContainer from '../services/AppContainer';
+import { createSubscribedElement } from './UnstatedUtils';
+
 class LoginForm extends React.Component {
 
   constructor(props) {
@@ -281,6 +284,13 @@ class LoginForm extends React.Component {
 
 }
 
+/**
+ * Wrapper component for using unstated
+ */
+const LoginFormWrapper = (props) => {
+  return createSubscribedElement(LoginForm, props, [AppContainer]);
+};
+
 LoginForm.propTypes = {
   // i18next
   t: PropTypes.func.isRequired,
@@ -291,4 +301,4 @@ LoginForm.propTypes = {
   csrf: PropTypes.string,
 };
 
-export default withTranslation()(LoginForm);
+export default withTranslation()(LoginFormWrapper);

+ 8 - 7
src/client/js/nologin.jsx

@@ -1,5 +1,6 @@
 import React from 'react';
 import ReactDOM from 'react-dom';
+import { Provider } from 'unstated';
 import { I18nextProvider } from 'react-i18next';
 
 import i18nFactory from './util/i18n';
@@ -7,8 +8,12 @@ import i18nFactory from './util/i18n';
 import InstallerForm from './components/InstallerForm';
 import LoginForm from './components/LoginForm';
 
+import AppContainer from './services/AppContainer';
+
 const i18n = i18nFactory();
 
+const nologinContainer = new AppContainer();
+
 // render InstallerForm
 const installerFormElem = document.getElementById('installer-form');
 if (installerFormElem) {
@@ -36,13 +41,9 @@ if (loginFormElem) {
 
   ReactDOM.render(
     <I18nextProvider i18n={i18n}>
-      <LoginForm
-        isRegistering={isRegistering}
-        username={username}
-        name={name}
-        email={email}
-        csrf={csrf}
-      />
+      <Provider inject={[nologinContainer]}>
+        <LoginForm isRegistering={isRegistering} username={username} name={name} email={email} csrf={csrf} />
+      </Provider>
     </I18nextProvider>,
     loginFormElem,
   );