Răsfoiți Sursa

move testConnection etc

zahmis 4 ani în urmă
părinte
comite
c198840540

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

@@ -9,12 +9,15 @@ import CustomBotWithoutProxyIntegrationCard from './CustomBotWithoutProxyIntegra
 import DeleteSlackBotSettingsModal from './DeleteSlackBotSettingsModal';
 import DeleteSlackBotSettingsModal from './DeleteSlackBotSettingsModal';
 
 
 const CustomBotWithoutProxySettings = (props) => {
 const CustomBotWithoutProxySettings = (props) => {
-  const { appContainer, onResetSettings } = props;
+  const { appContainer, onResetSettings, onSetIsSendTestMessage } = props;
   const { t } = useTranslation();
   const { t } = useTranslation();
 
 
   const [siteName, setSiteName] = useState('');
   const [siteName, setSiteName] = useState('');
   const [isDeleteConfirmModalShown, setIsDeleteConfirmModalShown] = useState(false);
   const [isDeleteConfirmModalShown, setIsDeleteConfirmModalShown] = useState(false);
   const [isIntegrationSuccess, setIsIntegrationSuccess] = useState(false);
   const [isIntegrationSuccess, setIsIntegrationSuccess] = useState(false);
+  const [connectionMessage, setConnectionMessage] = useState(null);
+  const [connectionErrorCode, setConnectionErrorCode] = useState(null);
+  const [testChannel, setTestChannel] = useState('');
 
 
   const resetSettings = async() => {
   const resetSettings = async() => {
     if (onResetSettings == null) {
     if (onResetSettings == null) {
@@ -25,22 +28,25 @@ const CustomBotWithoutProxySettings = (props) => {
 
 
   const testConnection = async() => {
   const testConnection = async() => {
     setConnectionErrorCode(null);
     setConnectionErrorCode(null);
-    setConnectionErrorMessage(null);
-    setConnectionSuccessMessage(null);
+    setConnectionMessage(null);
     try {
     try {
       await appContainer.apiv3.post('/slack-integration-settings/without-proxy/test', { channel: testChannel });
       await appContainer.apiv3.post('/slack-integration-settings/without-proxy/test', { channel: testChannel });
-      setConnectionSuccessMessage('Send to message to slack ws.');
+      setConnectionMessage('Send message to slack ws.');
       onSetIsSendTestMessage(true);
       onSetIsSendTestMessage(true);
-      onSetIsIntegrationSuccess(true);
+      setIsIntegrationSuccess(true);
     }
     }
     catch (err) {
     catch (err) {
       setConnectionErrorCode(err[0].code);
       setConnectionErrorCode(err[0].code);
-      setConnectionErrorMessage(err[0].message);
+      setConnectionMessage(err[0].message);
       onSetIsSendTestMessage(false);
       onSetIsSendTestMessage(false);
-      onSetIsIntegrationSuccess(false);
+      setIsIntegrationSuccess(false);
     }
     }
   };
   };
 
 
+  const inputTestChannelHandler = (channel) => {
+    setTestChannel(channel);
+  };
+
   useEffect(() => {
   useEffect(() => {
     const siteName = appContainer.config.crowi.title;
     const siteName = appContainer.config.crowi.title;
     setSiteName(siteName);
     setSiteName(siteName);
@@ -71,6 +77,11 @@ const CustomBotWithoutProxySettings = (props) => {
         <CustomBotWithoutProxySettingsAccordion
         <CustomBotWithoutProxySettingsAccordion
           {...props}
           {...props}
           activeStep={botInstallationStep.CREATE_BOT}
           activeStep={botInstallationStep.CREATE_BOT}
+          onTestConnection={testConnection}
+          onInputTestChannelHandler={inputTestChannelHandler}
+          connectionMessage={connectionMessage}
+          connectionErrorCode={connectionErrorCode}
+          testChannel={testChannel}
         />
         />
       </div>
       </div>
       <DeleteSlackBotSettingsModal
       <DeleteSlackBotSettingsModal
@@ -96,6 +107,7 @@ CustomBotWithoutProxySettings.propTypes = {
   isIntegrationSuccess: PropTypes.bool,
   isIntegrationSuccess: PropTypes.bool,
   slackWSNameInWithoutProxy: PropTypes.string,
   slackWSNameInWithoutProxy: PropTypes.string,
   onResetSettings: PropTypes.func,
   onResetSettings: PropTypes.func,
+  onSetIsSendTestMessage: PropTypes.func,
 };
 };
 
 
 export default CustomBotWithoutProxySettingsWrapper;
 export default CustomBotWithoutProxySettingsWrapper;

+ 24 - 40
src/client/js/components/Admin/SlackIntegration/CustomBotWithoutProxySettingsAccordion.jsx

@@ -16,19 +16,15 @@ export const botInstallationStep = {
 };
 };
 
 
 const CustomBotWithoutProxySettingsAccordion = ({
 const CustomBotWithoutProxySettingsAccordion = ({
-  appContainer, activeStep, fetchSlackIntegrationData,
+  appContainer, activeStep, fetchSlackIntegrationData, connectionMessage, connectionErrorCode, testChannel,
   slackSigningSecret, slackSigningSecretEnv, slackBotToken, slackBotTokenEnv,
   slackSigningSecret, slackSigningSecretEnv, slackBotToken, slackBotTokenEnv,
   isRegisterSlackCredentials, isSendTestMessage,
   isRegisterSlackCredentials, isSendTestMessage,
-  onSetSlackSigningSecret, onSetSlackBotToken, onSetIsSendTestMessage, onSetIsIntegrationSuccess,
+  onSetSlackSigningSecret, onSetSlackBotToken, onTestConnection, onInputTestChannelHandler,
 }) => {
 }) => {
   const { t } = useTranslation();
   const { t } = useTranslation();
   // TODO: GW-5644 Store default open accordion
   // TODO: GW-5644 Store default open accordion
   // eslint-disable-next-line no-unused-vars
   // eslint-disable-next-line no-unused-vars
   const [defaultOpenAccordionKeys, setDefaultOpenAccordionKeys] = useState(new Set([activeStep]));
   const [defaultOpenAccordionKeys, setDefaultOpenAccordionKeys] = useState(new Set([activeStep]));
-  const [connectionErrorCode, setConnectionErrorCode] = useState(null);
-  const [connectionErrorMessage, setConnectionErrorMessage] = useState(null);
-  const [connectionSuccessMessage, setConnectionSuccessMessage] = useState(null);
-  const [testChannel, setTestChannel] = useState('');
   const currentBotType = 'customBotWithoutProxy';
   const currentBotType = 'customBotWithoutProxy';
 
 
 
 
@@ -63,39 +59,19 @@ const CustomBotWithoutProxySettingsAccordion = ({
     }
     }
   };
   };
 
 
-  const testConnection = async() => {
-    setConnectionErrorCode(null);
-    setConnectionErrorMessage(null);
-    setConnectionSuccessMessage(null);
-    try {
-      await appContainer.apiv3.post('/slack-integration-settings/without-proxy/test', { channel: testChannel });
-      setConnectionSuccessMessage('Send to message to slack ws.');
-      onSetIsSendTestMessage(true);
-      onSetIsIntegrationSuccess(true);
-    }
-    catch (err) {
-      setConnectionErrorCode(err[0].code);
-      setConnectionErrorMessage(err[0].message);
-      onSetIsSendTestMessage(false);
-      onSetIsIntegrationSuccess(false);
-    }
-  };
 
 
   const submitForm = (e) => {
   const submitForm = (e) => {
     e.preventDefault();
     e.preventDefault();
-    testConnection();
+    onTestConnection();
   };
   };
 
 
-  const inputTestChannelHandler = (channel) => {
-    setTestChannel(channel);
-  };
 
 
   let value = '';
   let value = '';
-  if (connectionErrorMessage != null) {
-    value = [connectionErrorCode, connectionErrorMessage];
+  if (connectionMessage === 'Send message to slack ws.' || connectionMessage == null) {
+    value = connectionMessage;
   }
   }
-  if (connectionSuccessMessage != null) {
-    value = connectionSuccessMessage;
+  else {
+    value = [connectionErrorCode, connectionMessage];
   }
   }
 
 
   return (
   return (
@@ -170,7 +146,7 @@ const CustomBotWithoutProxySettingsAccordion = ({
                 type="text"
                 type="text"
                 value={testChannel}
                 value={testChannel}
                 placeholder="Slack Channel"
                 placeholder="Slack Channel"
-                onChange={e => inputTestChannelHandler(e.target.value)}
+                onChange={e => onInputTestChannelHandler(e.target.value)}
               />
               />
             </div>
             </div>
             <button
             <button
@@ -181,10 +157,17 @@ const CustomBotWithoutProxySettingsAccordion = ({
             </button>
             </button>
           </form>
           </form>
         </div>
         </div>
-        {connectionErrorMessage != null
-          && <p className="text-danger text-center my-4">{t('admin:slack_integration.accordion.error_check_logs_below')}</p>}
-        {connectionSuccessMessage != null
-          && <p className="text-info text-center my-4">{t('admin:slack_integration.accordion.send_message_to_slack_work_space')}</p>}
+        {connectionMessage == null
+          ? <p></p>
+          : (
+            <>
+              {connectionMessage === 'Send message to slack ws.'
+                ? <p className="text-info text-center my-4">{t('admin:slack_integration.accordion.send_message_to_slack_work_space')}</p>
+                : <p className="text-danger text-center my-4">{t('admin:slack_integration.accordion.error_check_logs_below')}</p>
+              }
+            </>
+          )
+        }
         <form>
         <form>
           <div className="row my-3 justify-content-center">
           <div className="row my-3 justify-content-center">
             <div className="form-group slack-connection-log col-md-4">
             <div className="form-group slack-connection-log col-md-4">
@@ -211,16 +194,17 @@ CustomBotWithoutProxySettingsAccordion.propTypes = {
   slackSigningSecretEnv: PropTypes.string,
   slackSigningSecretEnv: PropTypes.string,
   slackBotToken: PropTypes.string,
   slackBotToken: PropTypes.string,
   slackBotTokenEnv: PropTypes.string,
   slackBotTokenEnv: PropTypes.string,
+  testChannel: PropTypes.string,
   isRegisterSlackCredentials: PropTypes.bool,
   isRegisterSlackCredentials: PropTypes.bool,
   isSendTestMessage: PropTypes.bool,
   isSendTestMessage: PropTypes.bool,
   fetchSlackIntegrationData: PropTypes.func,
   fetchSlackIntegrationData: PropTypes.func,
   onSetSlackSigningSecret: PropTypes.func,
   onSetSlackSigningSecret: PropTypes.func,
   onSetSlackBotToken: PropTypes.func,
   onSetSlackBotToken: PropTypes.func,
-  onSetIsSendTestMessage: PropTypes.func,
   onSetIsRegisterSlackCredentials: PropTypes.func,
   onSetIsRegisterSlackCredentials: PropTypes.func,
-  setSlackWSNameInWithoutProxy: PropTypes.func,
-  onSetIsIntegrationSuccess: PropTypes.func,
-
+  onInputTestChannelHandler: PropTypes.func,
+  onTestConnection: PropTypes.func,
+  connectionMessage: PropTypes.string,
+  connectionErrorCode: PropTypes.string,
   adminAppContainer: PropTypes.instanceOf(AdminAppContainer).isRequired,
   adminAppContainer: PropTypes.instanceOf(AdminAppContainer).isRequired,
   activeStep: PropTypes.oneOf(Object.values(botInstallationStep)).isRequired,
   activeStep: PropTypes.oneOf(Object.values(botInstallationStep)).isRequired,
 };
 };