zahmis %!s(int64=4) %!d(string=hai) anos
pai
achega
2924a68191

+ 32 - 32
src/client/js/components/Admin/SlackIntegration/CustomBotWithoutProxySettings.jsx

@@ -2,38 +2,38 @@ import React, { useState, useEffect } from 'react';
 import { useTranslation } from 'react-i18next';
 import PropTypes from 'prop-types';
 import AppContainer from '../../../services/AppContainer';
-import AdminAppContainer from '../../../services/AdminAppContainer';
+// import AdminAppContainer from '../../../services/AdminAppContainer';
 import { withUnstatedContainers } from '../../UnstatedUtils';
 import CustomBotWithoutProxySettingsAccordion, { botInstallationStep } from './CustomBotWithoutProxySettingsAccordion';
 import CustomBotWithoutProxyConnectionStatus from './CustomBotWithoutProxyConnectionStatus';
-import { addLogs } from './slak-integration-util';
+// import { addLogs } from './slak-integration-util';
 
 const CustomBotWithoutProxySettings = (props) => {
-  const { appContainer, connectionStatuses, onTestConnectionInvoked } = props;
+  const { appContainer, connectionStatuses } = props;
   const { t } = useTranslation();
 
   const [siteName, setSiteName] = useState('');
-  const [isLatestConnectionSuccess, setIsLatestConnectionSuccess] = useState(false);
-  const [latestConnectionMessage, setLatestConnectionMessage] = useState(null);
-  const [testChannel, setTestChannel] = useState('');
-
-  const testConnection = async() => {
-    try {
-      await appContainer.apiv3.post('/slack-integration-settings/without-proxy/test', { channel: testChannel });
-      setIsLatestConnectionSuccess(true);
-      if (onTestConnectionInvoked != null) {
-        onTestConnectionInvoked();
-      }
-    }
-    catch (err) {
-      setIsLatestConnectionSuccess(false);
-      setLatestConnectionMessage(addLogs(latestConnectionMessage, err[0].message, err[0].code));
-    }
-  };
-
-  const inputTestChannelHandler = (channel) => {
-    setTestChannel(channel);
-  };
+  // const [isLatestConnectionSuccess, setIsLatestConnectionSuccess] = useState(false);
+  // const [latestConnectionMessage, setLatestConnectionMessage] = useState(null);
+  // const [testChannel, setTestChannel] = useState('');
+
+  // const testConnection = async() => {
+  //   try {
+  //     await appContainer.apiv3.post('/slack-integration-settings/without-proxy/test', { channel: testChannel });
+  //     setIsLatestConnectionSuccess(true);
+  //     if (onTestConnectionInvoked != null) {
+  //       onTestConnectionInvoked();
+  //     }
+  //   }
+  //   catch (err) {
+  //     setIsLatestConnectionSuccess(false);
+  //     setLatestConnectionMessage(addLogs(latestConnectionMessage, err[0].message, err[0].code));
+  //   }
+  // };
+
+  // const inputTestChannelHandler = (channel) => {
+  //   setTestChannel(channel);
+  // };
 
   useEffect(() => {
     const siteName = appContainer.config.crowi.title;
@@ -66,22 +66,22 @@ const CustomBotWithoutProxySettings = (props) => {
         <CustomBotWithoutProxySettingsAccordion
           {...props}
           activeStep={botInstallationStep.CREATE_BOT}
-          isLatestConnectionSuccess={isLatestConnectionSuccess}
-          latestConnectionMessage={latestConnectionMessage}
-          testChannel={testChannel}
-          onTestFormSubmitted={testConnection}
-          inputTestChannelHandler={inputTestChannelHandler}
+          // isLatestConnectionSuccess={isLatestConnectionSuccess}
+          // latestConnectionMessage={latestConnectionMessage}
+          // testChannel={testChannel}
+          // onTestFormSubmitted={testConnection}
+          // inputTestChannelHandler={inputTestChannelHandler}
         />
       </div>
     </>
   );
 };
 
-const CustomBotWithoutProxySettingsWrapper = withUnstatedContainers(CustomBotWithoutProxySettings, [AppContainer, AdminAppContainer]);
+const CustomBotWithoutProxySettingsWrapper = withUnstatedContainers(CustomBotWithoutProxySettings, [AppContainer]);
 
 CustomBotWithoutProxySettings.propTypes = {
   appContainer: PropTypes.instanceOf(AppContainer).isRequired,
-  adminAppContainer: PropTypes.instanceOf(AdminAppContainer).isRequired,
+  // adminAppContainer: PropTypes.instanceOf(AdminAppContainer).isRequired,
 
   slackSigningSecret: PropTypes.string,
   slackSigningSecretEnv: PropTypes.string,
@@ -89,7 +89,7 @@ CustomBotWithoutProxySettings.propTypes = {
   slackBotTokenEnv: PropTypes.string,
 
   connectionStatuses: PropTypes.object.isRequired,
-  onTestConnectionInvoked: PropTypes.func,
+  // onTestConnectionInvoked: PropTypes.func,
 };
 
 export default CustomBotWithoutProxySettingsWrapper;

+ 34 - 14
src/client/js/components/Admin/SlackIntegration/CustomBotWithoutProxySettingsAccordion.jsx

@@ -2,7 +2,11 @@ import React, { useState } from 'react';
 import PropTypes from 'prop-types';
 import { useTranslation } from 'react-i18next';
 import Accordion from '../Common/Accordion';
+import AppContainer from '../../../services/AppContainer';
+import { withUnstatedContainers } from '../../UnstatedUtils';
 import CustomBotWithoutProxySecretTokenSection from './CustomBotWithoutProxySecretTokenSection';
+import { addLogs } from './slak-integration-util';
+
 
 export const botInstallationStep = {
   CREATE_BOT: 'create-bot',
@@ -33,23 +37,39 @@ MessageBasedOnConnection.propTypes = {
 
 const CustomBotWithoutProxySettingsAccordion = (props) => {
   const {
-    activeStep, latestConnectionMessage, isLatestConnectionSuccess, testChannel,
-    slackSigningSecret, slackBotToken, slackSigningSecretEnv, slackBotTokenEnv,
-    inputTestChannelHandler, onTestFormSubmitted,
+    appContainer, activeStep, slackSigningSecret, slackBotToken, slackSigningSecretEnv, slackBotTokenEnv, onTestConnectionInvoked,
   } = props;
 
   const { t } = useTranslation();
-  // TODO: GW-5644 Store default open accordion
   // eslint-disable-next-line no-unused-vars
   const [defaultOpenAccordionKeys, setDefaultOpenAccordionKeys] = useState(new Set([activeStep]));
+  const [latestConnectionMessage, setLatestConnectionMessage] = useState(null);
+  const [isLatestConnectionSuccess, setIsLatestConnectionSuccess] = useState(false);
+  const [testChannel, setTestChannel] = useState('');
+
+  const testConnection = async() => {
+    try {
+      await appContainer.apiv3.post('/slack-integration-settings/without-proxy/test', { channel: testChannel });
+      setIsLatestConnectionSuccess(true);
+      if (onTestConnectionInvoked != null) {
+        onTestConnectionInvoked();
+      }
+    }
+    catch (err) {
+      setIsLatestConnectionSuccess(false);
+      setLatestConnectionMessage(addLogs(latestConnectionMessage, err[0].message, err[0].code));
+    }
+  };
+
+  const inputTestChannelHandler = (channel) => {
+    setTestChannel(channel);
+  };
+
 
   const submitForm = (e) => {
     e.preventDefault();
 
-    if (onTestFormSubmitted == null) {
-      return;
-    }
-    onTestFormSubmitted();
+    testConnection();
   };
 
   let logsValue = null;
@@ -170,8 +190,12 @@ const CustomBotWithoutProxySettingsAccordion = (props) => {
 };
 
 
+const CustomBotWithoutProxySettingsAccordionWrapper = withUnstatedContainers(CustomBotWithoutProxySettingsAccordion, [AppContainer]);
+
+
 CustomBotWithoutProxySettingsAccordion.propTypes = {
   activeStep: PropTypes.oneOf(Object.values(botInstallationStep)).isRequired,
+  appContainer: PropTypes.instanceOf(AppContainer).isRequired,
 
   onUpdatedSecretToken: PropTypes.func,
   slackSigningSecret: PropTypes.string,
@@ -179,11 +203,7 @@ CustomBotWithoutProxySettingsAccordion.propTypes = {
   slackBotToken: PropTypes.string,
   slackBotTokenEnv: PropTypes.string,
 
-  isLatestConnectionSuccess: PropTypes.bool,
-  latestConnectionMessage: PropTypes.string,
-  testChannel: PropTypes.string,
-  inputTestChannelHandler: PropTypes.func,
-  onTestFormSubmitted: PropTypes.func,
+  onTestConnectionInvoked: PropTypes.func,
 };
 
-export default CustomBotWithoutProxySettingsAccordion;
+export default CustomBotWithoutProxySettingsAccordionWrapper;