yusuketk 6 лет назад
Родитель
Сommit
cf1c7650d6

+ 6 - 22
src/client/js/components/Admin/App/AppSetting.jsx

@@ -15,11 +15,13 @@ class AppSetting extends React.Component {
   constructor(props) {
     super(props);
 
+    const currentValues = props;
+
     this.state = {
-      title: '',
-      confidential: '',
-      globalLang: 'en-US',
-      fileUpload: false,
+      title: currentValues.title,
+      confidential: currentValues.confidential,
+      globalLang: currentValues.globalLang,
+      fileUpload: currentValues.fileUpload,
     };
 
     this.submitHandler = this.submitHandler.bind(this);
@@ -29,24 +31,6 @@ class AppSetting extends React.Component {
     this.inputFileUploadChangeHandler = this.inputFileUploadChangeHandler.bind(this);
   }
 
-  async componentDidMount() {
-    try {
-      const response = await this.props.appContainer.apiv3.get('/app-settings/');
-      const appSettingParams = response.data.appSettingParams;
-
-      this.setState({
-        title: appSettingParams.title || '',
-        confidential: appSettingParams.confidential || '',
-        globalLang: appSettingParams.globalLang || 'en-US',
-        fileUpload: appSettingParams.fileUpload || false,
-      });
-    }
-    catch (err) {
-      toastError(err);
-      logger.error(err);
-    }
-  }
-
   async submitHandler() {
     const { t } = this.props;
 

+ 6 - 22
src/client/js/components/Admin/App/SiteUrlSetting.jsx

@@ -15,34 +15,18 @@ class SiteUrlSetting extends React.Component {
   constructor(props) {
     super(props);
 
+    const currentValues = props;
+
     this.state = {
-      siteUrl: '',
-      envSiteUrl: '',
-      isSettingSiteUrl: true,
+      siteUrl: currentValues.siteUrl,
+      envSiteUrl: currentValues.envSiteUrl,
+      isSetSiteUrl: currentValues.isSetSiteUrl,
     };
 
-    this.envSiteUrl = '';
     this.submitHandler = this.submitHandler.bind(this);
     this.inputSiteUrlChangeHandler = this.inputSiteUrlChangeHandler.bind(this);
   }
 
-  async componentDidMount() {
-    try {
-      const response = await this.props.appContainer.apiv3.get('/app-settings/');
-      const appSettingParams = response.data.appSettingParams;
-
-      this.setState({
-        siteUrl: appSettingParams.siteUrl || appSettingParams.envSiteUrl || '',
-        envSiteUrl: appSettingParams.envSiteUrl || '',
-        isSettingSiteUrl: !!appSettingParams.siteUrl,
-      });
-    }
-    catch (err) {
-      toastError(err);
-      logger.error(err);
-    }
-  }
-
   async submitHandler() {
     const { t } = this.props;
 
@@ -70,7 +54,7 @@ class SiteUrlSetting extends React.Component {
     return (
       <React.Fragment>
         <p className="well">{t('app_setting.Site URL desc')}</p>
-        {!this.state.isSettingSiteUrl && (<p className="alert alert-danger"><i className="icon-exclamation"></i> {t('app_setting.Site URL warn')}</p>)}
+        {!this.state.isSetSiteUrl && (<p className="alert alert-danger"><i className="icon-exclamation"></i> {t('app_setting.Site URL warn')}</p>)}
 
         <div className="row">
           <div className="col-md-12">

+ 44 - 2
src/client/js/components/Admin/AppSettingPage.jsx

@@ -1,8 +1,10 @@
 import React, { Fragment } from 'react';
 import { withTranslation } from 'react-i18next';
 import PropTypes from 'prop-types';
+import loggerFactory from '@alias/logger';
 
 import { createSubscribedElement } from '../UnstatedUtils';
+import { toastError } from '../../util/apiNotification';
 
 import AppContainer from '../../services/AppContainer';
 
@@ -12,12 +14,43 @@ import MailSetting from './App/MailSetting';
 import AwsSetting from './App/AwsSetting';
 import PluginSetting from './App/PluginSetting';
 
+const logger = loggerFactory('growi:appSettings');
+
 class AppSettingPage extends React.Component {
 
   constructor(props) {
     super(props);
     this.state = {
+      title: '',
+      confidential: '',
+      globalLang: '',
+      fileUpload: '',
+      siteUrl: '',
+      envSiteUrl: '',
+      isSetSiteUrl: true,
     };
+
+  }
+
+  async componentDidMount() {
+    try {
+      const response = await this.props.appContainer.apiv3.get('/app-settings/');
+      const appSettingParams = response.data.appSettingParams;
+
+      this.setState({
+        title: appSettingParams.title || '',
+        confidential: appSettingParams.confidential || '',
+        globalLang: appSettingParams.globalLang || 'en-US',
+        fileUpload: appSettingParams.fileUpload || false,
+        siteUrl: appSettingParams.siteUrl || appSettingParams.envSiteUrl || '',
+        envSiteUrl: appSettingParams.envSiteUrl || '',
+        isSetSiteUrl: !!appSettingParams.siteUrl,
+      });
+    }
+    catch (err) {
+      toastError(err);
+      logger.error(err);
+    }
   }
 
   render() {
@@ -28,14 +61,23 @@ class AppSettingPage extends React.Component {
         <div className="row">
           <div className="col-md-12">
             <h2>{t('App Settings')}</h2>
-            <AppSetting />
+            <AppSetting
+              title={this.state.title}
+              confidential={this.state.confidential}
+              globalLang={this.state.globalLang}
+              fileUpload={this.state.fileUpload}
+            />
           </div>
         </div>
 
         <div className="row">
           <div className="col-md-12">
             <h2>{t('Site URL settings')}</h2>
-            <SiteUrlSetting />
+            <SiteUrlSetting
+              siteUrl={this.state.siteUrl}
+              envSiteUrl={this.state.envSiteUrl}
+              isSetSiteUrl={this.state.isSetSiteUrl}
+            />
           </div>
         </div>