فهرست منبع

Added toaster and refactored code

Steven Fukase 5 سال پیش
والد
کامیت
3d38ecb43a

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

@@ -253,6 +253,7 @@
     "delete": "Delete"
   },
   "slack_integration": {
+    "bot_reset_successful": "Bot settings have been reset.",
     "modal": {
       "warning": "Warning",
       "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": "ディレクトリ階層タグ"
   },
   "slack_integration": {
+    "bot_reset_successful": "Botの設定を消去しました。",
     "modal": {
       "warning": "注意",
       "sure_change_bot_type": "Botの種類を変更しますか?",

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

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

+ 18 - 20
src/client/js/components/Admin/SlackIntegration/SlackIntegration.jsx

@@ -1,8 +1,9 @@
 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 { toastError } from '../../../util/apiNotification';
+import { toastSuccess, toastError } from '../../../util/apiNotification';
 import AccessTokenSettings from './AccessTokenSettings';
 import OfficialBotSettings from './OfficialBotSettings';
 import CustomBotWithoutProxySettings from './CustomBotWithoutProxySettings';
@@ -11,23 +12,10 @@ import ConfirmBotChangeModal from './ConfirmBotChangeModal';
 
 const SlackIntegration = (props) => {
   const { appContainer } = props;
-
+  const { t } = useTranslation();
   const [currentBotType, setCurrentBotType] = useState(null);
   const [selectedBotType, setSelectedBotType] = useState(null);
 
-  const resetBotType = async() => {
-    try {
-      await appContainer.apiv3.put('slack-integration/custom-bot-without-proxy', {
-        slackSigningSecret: '',
-        slackBotToken: '',
-        botType: '',
-      });
-    }
-    catch (err) {
-      toastError(err);
-    }
-  };
-
   const handleBotTypeSelect = (clickedBotType) => {
     if (clickedBotType === currentBotType) {
       return;
@@ -43,10 +31,20 @@ const SlackIntegration = (props) => {
     setSelectedBotType(null);
   };
 
-  const changeCurrentBotSettings = () => {
-    resetBotType();
-    setCurrentBotType(selectedBotType);
-    setSelectedBotType(null);
+  const handleChangeCurrentBotSettings = async() => {
+    try {
+      await appContainer.apiv3.put('slack-integration/custom-bot-without-proxy', {
+        slackSigningSecret: '',
+        slackBotToken: '',
+        botType: '',
+      });
+      setCurrentBotType(selectedBotType);
+      setSelectedBotType(null);
+      toastSuccess(t('toaster.update_successed'), { target: t('admin:slack_integration.bot_reset_successful') });
+    }
+    catch (err) {
+      toastError(err);
+    }
   };
 
   let settingsComponent = null;
@@ -68,7 +66,7 @@ const SlackIntegration = (props) => {
       <div className="container">
         <ConfirmBotChangeModal
           isOpen={selectedBotType != null}
-          onConfirmClick={changeCurrentBotSettings}
+          onConfirmClick={handleChangeCurrentBotSettings}
           onCancelClick={handleCancelBotChange}
         />
       </div>