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

Merge pull request #3578 from weseek/feat/5529-delete-info-from-backend

Feat/5529 delete info from backend
itizawa 5 жил өмнө
parent
commit
7c15010450

+ 1 - 0
resource/locales/en_US/admin/admin.json

@@ -253,6 +253,7 @@
     "delete": "Delete"
     "delete": "Delete"
   },
   },
   "slack_integration": {
   "slack_integration": {
+    "bot_reset_successful": "Bot settings have been reset.",
     "modal": {
     "modal": {
       "warning": "Warning",
       "warning": "Warning",
       "sure_change_bot_type": "Are you sure you want to change the bot type?",
       "sure_change_bot_type": "Are you sure you want to change the bot type?",

+ 1 - 0
resource/locales/ja_JP/admin/admin.json

@@ -251,6 +251,7 @@
     "Directory_hierarchy_tag": "ディレクトリ階層タグ"
     "Directory_hierarchy_tag": "ディレクトリ階層タグ"
   },
   },
   "slack_integration": {
   "slack_integration": {
+    "bot_reset_successful": "Botの設定を消去しました。",
     "modal": {
     "modal": {
       "warning": "注意",
       "warning": "注意",
       "sure_change_bot_type": "Botの種類を変更しますか?",
       "sure_change_bot_type": "Botの種類を変更しますか?",

+ 1 - 0
resource/locales/zh_CN/admin/admin.json

@@ -261,6 +261,7 @@
 		"delete": "删除"
 		"delete": "删除"
   },
   },
   "slack_integration": {
   "slack_integration": {
+    "bot_reset_successful": "删除了BOT设置。",
     "modal": {
     "modal": {
       "warning": "警告",
       "warning": "警告",
       "sure_change_bot_type": "您确定要更改设置吗?",
       "sure_change_bot_type": "您确定要更改设置吗?",

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

@@ -1,12 +1,18 @@
 import React, { useState } from 'react';
 import React, { useState } from 'react';
-
+import PropTypes from 'prop-types';
+import { useTranslation } from 'react-i18next';
+import AppContainer from '../../../services/AppContainer';
+import { withUnstatedContainers } from '../../UnstatedUtils';
+import { toastSuccess, toastError } from '../../../util/apiNotification';
 import AccessTokenSettings from './AccessTokenSettings';
 import AccessTokenSettings from './AccessTokenSettings';
 import OfficialBotSettings from './OfficialBotSettings';
 import OfficialBotSettings from './OfficialBotSettings';
 import CustomBotWithoutProxySettings from './CustomBotWithoutProxySettings';
 import CustomBotWithoutProxySettings from './CustomBotWithoutProxySettings';
 import CustomBotWithProxySettings from './CustomBotWithProxySettings';
 import CustomBotWithProxySettings from './CustomBotWithProxySettings';
 import ConfirmBotChangeModal from './ConfirmBotChangeModal';
 import ConfirmBotChangeModal from './ConfirmBotChangeModal';
 
 
-const SlackIntegration = () => {
+const SlackIntegration = (props) => {
+  const { appContainer } = props;
+  const { t } = useTranslation();
   const [currentBotType, setCurrentBotType] = useState(null);
   const [currentBotType, setCurrentBotType] = useState(null);
   const [selectedBotType, setSelectedBotType] = useState(null);
   const [selectedBotType, setSelectedBotType] = useState(null);
 
 
@@ -25,9 +31,20 @@ const SlackIntegration = () => {
     setSelectedBotType(null);
     setSelectedBotType(null);
   };
   };
 
 
-  const changeCurrentBotSettings = () => {
-    setCurrentBotType(selectedBotType);
-    setSelectedBotType(null);
+  const handleChangeCurrentBotSettings = async() => {
+    try {
+      const res = await appContainer.apiv3.put('slack-integration/custom-bot-without-proxy', {
+        slackSigningSecret: '',
+        slackBotToken: '',
+        botType: selectedBotType,
+      });
+      setCurrentBotType(res.data.customBotWithoutProxySettingParams.slackBotType);
+      setSelectedBotType(null);
+      toastSuccess(t('admin:slack_integration.bot_reset_successful'));
+    }
+    catch (err) {
+      toastError(err);
+    }
   };
   };
 
 
   let settingsComponent = null;
   let settingsComponent = null;
@@ -49,7 +66,7 @@ const SlackIntegration = () => {
       <div className="container">
       <div className="container">
         <ConfirmBotChangeModal
         <ConfirmBotChangeModal
           isOpen={selectedBotType != null}
           isOpen={selectedBotType != null}
-          onConfirmClick={changeCurrentBotSettings}
+          onConfirmClick={handleChangeCurrentBotSettings}
           onCancelClick={handleCancelBotChange}
           onCancelClick={handleCancelBotChange}
         />
         />
       </div>
       </div>
@@ -103,4 +120,10 @@ const SlackIntegration = () => {
   );
   );
 };
 };
 
 
-export default SlackIntegration;
+const SlackIntegrationWrapper = withUnstatedContainers(SlackIntegration, [AppContainer]);
+
+SlackIntegration.propTypes = {
+  appContainer: PropTypes.instanceOf(AppContainer).isRequired,
+};
+
+export default SlackIntegrationWrapper;