Browse Source

render with states of login container

yusuketk 6 years ago
parent
commit
47180fbe5d
2 changed files with 14 additions and 19 deletions
  1. 14 18
      src/client/js/components/LoginForm.jsx
  2. 0 1
      src/client/js/services/LoginContainer.js

+ 14 - 18
src/client/js/components/LoginForm.jsx

@@ -9,16 +9,10 @@ import { createSubscribedElement } from './UnstatedUtils';
 const logger = loggerFactory('growi:loginForm');
 const logger = loggerFactory('growi:loginForm');
 
 
 class LoginForm extends React.Component {
 class LoginForm extends React.Component {
+
   constructor(props) {
   constructor(props) {
     super(props);
     super(props);
 
 
-    this.isRegistrationEnabled = false;
-    this.registrationMode = 'Closed';
-    this.registrationWhiteList = [];
-    this.isLocalStrategySetup = false;
-    this.isLdapStrategySetup = false;
-    this.objOfIsExternalAuthEnableds = {};
-
     this.switchForm = this.switchForm.bind(this);
     this.switchForm = this.switchForm.bind(this);
     this.renderLocalOrLdapLoginForm = this.renderLocalOrLdapLoginForm.bind(this);
     this.renderLocalOrLdapLoginForm = this.renderLocalOrLdapLoginForm.bind(this);
     this.renderExternalAuthLoginForm = this.renderExternalAuthLoginForm.bind(this);
     this.renderExternalAuthLoginForm = this.renderExternalAuthLoginForm.bind(this);
@@ -113,7 +107,8 @@ class LoginForm extends React.Component {
   }
   }
 
 
   renderExternalAuthLoginForm() {
   renderExternalAuthLoginForm() {
-    const isExternalAuthCollapsible = this.isLocalStrategySetup || this.isLdapStrategySetup;
+    const { loginContainer } = this.props;
+    const isExternalAuthCollapsible = loginContainer.state.isLocalStrategySetup || loginContainer.state.isLdapStrategySetup;
     const collapsibleClass = isExternalAuthCollapsible ? 'collapse collapse-external-auth collapse-anchor' : '';
     const collapsibleClass = isExternalAuthCollapsible ? 'collapse collapse-external-auth collapse-anchor' : '';
 
 
     return (
     return (
@@ -122,8 +117,8 @@ class LoginForm extends React.Component {
         <div id="external-auth" className={`external-auth ${collapsibleClass}`}>
         <div id="external-auth" className={`external-auth ${collapsibleClass}`}>
           <div className="spacer"></div>
           <div className="spacer"></div>
           <div className="d-flex flex-row justify-content-between flex-wrap">
           <div className="d-flex flex-row justify-content-between flex-wrap">
-            {Object.keys(this.objOfIsExternalAuthEnableds).map(auth => {
-              if (!this.objOfIsExternalAuthEnableds[auth]) {
+            {Object.keys(loginContainer.state.objOfIsExternalAuthEnableds).map((auth) => {
+              if (!loginContainer.state.objOfIsExternalAuthEnableds[auth]) {
                 return;
                 return;
               }
               }
               return this.renderExternalAuthInput(auth);
               return this.renderExternalAuthInput(auth);
@@ -149,7 +144,7 @@ class LoginForm extends React.Component {
   }
   }
 
 
   renderRegisterForm() {
   renderRegisterForm() {
-    const { t, csrf } = this.props;
+    const { t, loginContainer, csrf } = this.props;
     return (
     return (
       <div className="back">
       <div className="back">
         {this.registrationMode === 'Restricted' && (
         {this.registrationMode === 'Restricted' && (
@@ -190,11 +185,11 @@ class LoginForm extends React.Component {
             <input type="email" className="form-control" placeholder={t('Email')} name="registerForm[email]" defaultValue={this.props.email} required />
             <input type="email" className="form-control" placeholder={t('Email')} name="registerForm[email]" defaultValue={this.props.email} required />
           </div>
           </div>
 
 
-          {this.registrationWhiteList.length > 0 && (
+          {loginContainer.state.registrationWhiteList.length > 0 && (
             <>
             <>
               <p className="form-text">{t('page_register.form_help.email')}</p>
               <p className="form-text">{t('page_register.form_help.email')}</p>
               <ul>
               <ul>
-                {this.registrationWhiteList.map(elem => {
+                {loginContainer.state.registrationWhiteList.map((elem) => {
                   return (
                   return (
                     <li>
                     <li>
                       <code>{{ elem }}</code>
                       <code>{{ elem }}</code>
@@ -242,11 +237,11 @@ class LoginForm extends React.Component {
   }
   }
 
 
   render() {
   render() {
-    const { t, isRegistering } = this.props;
+    const { t, loginContainer, isRegistering } = this.props;
 
 
-    const isLocalOrLdapStrategiesEnabled = this.isLocalStrategySetup || this.isLdapStrategySetup;
+    const isLocalOrLdapStrategiesEnabled = loginContainer.state.isLocalStrategySetup || loginContainer.state.isLdapStrategySetup;
     const registerFormClass = isRegistering ? 'to-flip' : '';
     const registerFormClass = isRegistering ? 'to-flip' : '';
-    const isSomeExternalAuthEnabled = Object.values(this.objOfIsExternalAuthEnableds).some(elem => elem);
+    const isSomeExternalAuthEnabled = Object.values(loginContainer.state.objOfIsExternalAuthEnableds).some(elem => elem);
 
 
     return (
     return (
       <div className={`login-dialog mx-auto flipper ${registerFormClass}`} id="login-dialog">
       <div className={`login-dialog mx-auto flipper ${registerFormClass}`} id="login-dialog">
@@ -255,7 +250,7 @@ class LoginForm extends React.Component {
             <div className="front">
             <div className="front">
               {isLocalOrLdapStrategiesEnabled && this.renderLocalOrLdapLoginForm()}
               {isLocalOrLdapStrategiesEnabled && this.renderLocalOrLdapLoginForm()}
               {isSomeExternalAuthEnabled && this.renderExternalAuthLoginForm()}
               {isSomeExternalAuthEnabled && this.renderExternalAuthLoginForm()}
-              {this.isRegistrationEnabled && (
+              {loginContainer.state.isRegistrationEnabled && (
                 <div className="row">
                 <div className="row">
                   <div className="col-12 text-right py-2">
                   <div className="col-12 text-right py-2">
                     <a href="#register" id="register" className="link-switch" onClick={this.switchForm}>
                     <a href="#register" id="register" className="link-switch" onClick={this.switchForm}>
@@ -265,7 +260,7 @@ class LoginForm extends React.Component {
                 </div>
                 </div>
               )}
               )}
             </div>
             </div>
-            {this.isRegistrationEnabled && this.renderRegisterForm()}
+            {loginContainer.state.isRegistrationEnabled && this.renderRegisterForm()}
             <a href="https://growi.org" className="link-growi-org pl-3">
             <a href="https://growi.org" className="link-growi-org pl-3">
               <span className="growi">GROWI</span>.<span className="org">ORG</span>
               <span className="growi">GROWI</span>.<span className="org">ORG</span>
             </a>
             </a>
@@ -274,6 +269,7 @@ class LoginForm extends React.Component {
       </div>
       </div>
     );
     );
   }
   }
+
 }
 }
 
 
 /**
 /**

+ 0 - 1
src/client/js/services/LoginContainer.js

@@ -53,7 +53,6 @@ export default class LoginForm extends Container {
         isLdapStrategySetup: data.isLdapStrategySetup,
         isLdapStrategySetup: data.isLdapStrategySetup,
         objOfIsExternalAuthEnableds: data.objOfIsExternalAuthEnableds,
         objOfIsExternalAuthEnableds: data.objOfIsExternalAuthEnableds,
       });
       });
-
     }
     }
     catch (err) {
     catch (err) {
       logger.error(err);
       logger.error(err);