فهرست منبع

Merge pull request #3718 from weseek/fix/behavior-when-clicked-reset-button

Fix/behavior when clicked reset button
Sizma yosimaz 4 سال پیش
والد
کامیت
63e6e69811

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

@@ -4,30 +4,22 @@ import PropTypes from 'prop-types';
 import AppContainer from '../../../services/AppContainer';
 import AdminAppContainer from '../../../services/AdminAppContainer';
 import { withUnstatedContainers } from '../../UnstatedUtils';
-import { toastSuccess, toastError } from '../../../util/apiNotification';
 import CustomBotWithoutProxySettingsAccordion, { botInstallationStep } from './CustomBotWithoutProxySettingsAccordion';
 import CustomBotWithoutProxyIntegrationCard from './CustomBotWithoutProxyIntegrationCard';
 import DeleteSlackBotSettingsModal from './DeleteSlackBotSettingsModal';
 
 const CustomBotWithoutProxySettings = (props) => {
-  const { appContainer } = props;
+  const { appContainer, onResetSettings } = props;
   const { t } = useTranslation();
 
   const [siteName, setSiteName] = useState('');
   const [isDeleteConfirmModalShown, setIsDeleteConfirmModalShown] = useState(false);
 
-  const deleteSlackSettingsHandler = async() => {
-    try {
-      await appContainer.apiv3.put('/slack-integration-settings/bot-type', {
-        slackSigningSecret: null,
-        slackBotToken: null,
-        currentBotType: null,
-      });
-      toastSuccess('success');
-    }
-    catch (err) {
-      toastError(err);
+  const resetSettings = async() => {
+    if (onResetSettings == null) {
+      return;
     }
+    onResetSettings();
   };
 
   useEffect(() => {
@@ -46,12 +38,14 @@ const CustomBotWithoutProxySettings = (props) => {
 
       <h2 className="admin-setting-header">{t('admin:slack_integration.custom_bot_without_proxy_settings')}</h2>
 
+      {(props.slackSigningSecret || props.slackBotToken) && (
       <button
         className="mx-3 pull-right btn text-danger border-danger"
         type="button"
         onClick={() => setIsDeleteConfirmModalShown(true)}
       >{t('admin:slack_integration.reset')}
       </button>
+      )}
 
       <div className="my-5 mx-3">
         <CustomBotWithoutProxySettingsAccordion
@@ -63,7 +57,7 @@ const CustomBotWithoutProxySettings = (props) => {
         isResetAll={false}
         isOpen={isDeleteConfirmModalShown}
         onClose={() => setIsDeleteConfirmModalShown(false)}
-        onClickDeleteButton={deleteSlackSettingsHandler}
+        onClickDeleteButton={resetSettings}
       />
     </>
   );
@@ -80,6 +74,7 @@ CustomBotWithoutProxySettings.propTypes = {
   slackBotTokenEnv: PropTypes.string,
   isRgisterSlackCredentials: PropTypes.bool,
   slackWSNameInWithoutProxy: PropTypes.string,
+  onResetSettings: PropTypes.func,
 };
 
 export default CustomBotWithoutProxySettingsWrapper;

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

@@ -40,7 +40,7 @@ const SlackIntegration = (props) => {
         setSlackWSNameInWithoutProxy(workspaceName);
       }
 
-      setCurrentBotType(currentBotType);
+      setCurrentBotType(data.currentBotType);
       setSlackSigningSecret(slackSigningSecret);
       setSlackBotToken(slackBotToken);
       setSlackSigningSecretEnv(slackSigningSecretEnvVars);
@@ -49,8 +49,18 @@ const SlackIntegration = (props) => {
     catch (err) {
       toastError(err);
     }
-  }, [appContainer.apiv3, currentBotType]);
+  }, [appContainer.apiv3]);
 
+  const resetWithOutSettings = async() => {
+    try {
+      await appContainer.apiv3.put('/slack-integration-settings/bot-type', { currentBotType: 'customBotWithoutProxy' });
+      fetchSlackIntegrationData();
+      toastSuccess(t('admin:slack_integration.bot_reset_successful'));
+    }
+    catch (error) {
+      toastError(error);
+    }
+  };
 
   useEffect(() => {
     fetchSlackIntegrationData();
@@ -78,12 +88,12 @@ const SlackIntegration = (props) => {
       });
       setCurrentBotType(res.data.slackBotTypeParam.slackBotType);
       setSelectedBotType(null);
-      toastSuccess(t('admin:slack_integration.bot_reset_successful'));
       setIsRegisterSlackCredentials(false);
       setSlackSigningSecret(null);
       setSlackBotToken(null);
       setIsSendTestMessage(false);
       setSlackWSNameInWithoutProxy(null);
+      toastSuccess(t('admin:slack_integration.bot_reset_successful'));
     }
     catch (err) {
       toastError(err);
@@ -109,6 +119,7 @@ const SlackIntegration = (props) => {
           onSetSlackSigningSecret={setSlackSigningSecret}
           onSetSlackBotToken={setSlackBotToken}
           onSetIsSendTestMessage={setIsSendTestMessage}
+          onResetSettings={resetWithOutSettings}
           fetchSlackIntegrationData={fetchSlackIntegrationData}
         />
       );

+ 4 - 1
src/server/routes/apiv3/slack-integration-settings.js

@@ -129,7 +129,10 @@ module.exports = (crowi) => {
 
     // retrieve connection statuses
     let connectionStatuses;
-    if (currentBotType === 'customBotWithoutProxy') {
+    if (currentBotType == null) {
+      // TODO imple null action
+    }
+    else if (currentBotType === 'customBotWithoutProxy') {
       const token = settings.slackBotToken;
       // check the token is not null
       if (token != null) {