2
0
Эх сурвалжийг харах

Merge pull request #3744 from weseek/fix/problem-not-reflected-when-selected-botType-at-first

Fix/problem not reflected when selected bot type at first
Yuki Takei 4 жил өмнө
parent
commit
33bef3181b

+ 2 - 2
src/client/js/components/Admin/SlackIntegration/BotTypeCard.jsx

@@ -35,7 +35,7 @@ const BotTypeCard = (props) => {
   return (
     <div
       className={`card admin-bot-card rounded border-radius-sm shadow ${props.isActive ? 'border-primary' : ''}`}
-      onClick={() => props.handleBotTypeSelect(botDetails[props.botType].botType)}
+      onClick={() => props.onBotTypeSelectHandler(botDetails[props.botType].botType)}
       role="button"
       key={props.botType}
     >
@@ -87,7 +87,7 @@ const BotTypeCard = (props) => {
 BotTypeCard.propTypes = {
   isActive: PropTypes.bool.isRequired,
   botType: PropTypes.string.isRequired,
-  handleBotTypeSelect: PropTypes.func.isRequired,
+  onBotTypeSelectHandler: PropTypes.func.isRequired,
 };
 
 export default BotTypeCard;

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

@@ -78,25 +78,10 @@ const SlackIntegration = (props) => {
     fetchSlackIntegrationData();
   }, [fetchSlackIntegrationData]);
 
-  const handleBotTypeSelect = (clickedBotType) => {
-    if (clickedBotType === currentBotType) {
-      return;
-    }
-    if (currentBotType === null) {
-      setCurrentBotType(clickedBotType);
-      return;
-    }
-    setSelectedBotType(clickedBotType);
-  };
-
-  const cancelBotChangeHandler = () => {
-    setSelectedBotType(null);
-  };
-
-  const changeCurrentBotSettingsHandler = async() => {
+  const changeCurrentBotSettings = async(botType) => {
     try {
       const res = await appContainer.apiv3.put('/slack-integration-settings/bot-type', {
-        currentBotType: selectedBotType,
+        currentBotType: botType,
       });
       setCurrentBotType(res.data.slackBotTypeParam.slackBotType);
       setSelectedBotType(null);
@@ -105,13 +90,31 @@ const SlackIntegration = (props) => {
       setSlackBotToken(null);
       setIsSendTestMessage(false);
       setSlackWSNameInWithoutProxy(null);
-      toastSuccess(t('admin:slack_integration.bot_reset_successful'));
     }
     catch (err) {
       toastError(err);
     }
   };
 
+  const botTypeSelectHandler = async(botType) => {
+    if (botType === currentBotType) {
+      return;
+    }
+    if (currentBotType == null) {
+      return changeCurrentBotSettings(botType);
+    }
+    setSelectedBotType(botType);
+  };
+
+  const changeCurrentBotSettingsHandler = async() => {
+    changeCurrentBotSettings(selectedBotType);
+    toastSuccess(t('admin:slack_integration.bot_reset_successful'));
+  };
+
+  const cancelBotChangeHandler = () => {
+    setSelectedBotType(null);
+  };
+
   let settingsComponent = null;
 
   switch (currentBotType) {
@@ -188,7 +191,7 @@ const SlackIntegration = (props) => {
                 <BotTypeCard
                   botType={botType}
                   isActive={currentBotType === botType}
-                  handleBotTypeSelect={handleBotTypeSelect}
+                  onBotTypeSelectHandler={botTypeSelectHandler}
                 />
               </div>
             );