Просмотр исходного кода

Request sending to clear previous bot settings

Steven Fukase 5 лет назад
Родитель
Сommit
8d3b5c0bc4
1 измененных файлов с 29 добавлено и 3 удалено
  1. 29 3
      src/client/js/components/Admin/SlackIntegration/SlackIntegration.jsx

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

@@ -1,15 +1,34 @@
 import React, { useState } from 'react';
-
+import PropTypes from 'prop-types';
+import AppContainer from '../../../services/AppContainer';
+import { withUnstatedContainers } from '../../UnstatedUtils';
+import { toastError } from '../../../util/apiNotification';
 import AccessTokenSettings from './AccessTokenSettings';
 import OfficialBotSettings from './OfficialBotSettings';
 import CustomBotWithoutProxySettings from './CustomBotWithoutProxySettings';
 import CustomBotWithProxySettings from './CustomBotWithProxySettings';
 import ConfirmBotChangeModal from './ConfirmBotChangeModal';
 
-const SlackIntegration = () => {
+const SlackIntegration = (props) => {
+  const { appContainer } = props;
+
   const [currentBotType, setCurrentBotType] = useState(null);
   const [selectedBotType, setSelectedBotType] = useState(null);
 
+  const resetBotType = async() => {
+    try {
+      const res = await appContainer.apiv3.put('slack-integration/custom-bot-without-proxy', {
+        slackSigningSecret: '',
+        slackBotToken: '',
+        botType: '',
+      });
+      console.log(res);
+    }
+    catch (err) {
+      toastError(err);
+    }
+  };
+
   const handleBotTypeSelect = (clickedBotType) => {
     if (clickedBotType === currentBotType) {
       return;
@@ -26,6 +45,7 @@ const SlackIntegration = () => {
   };
 
   const changeCurrentBotSettings = () => {
+    resetBotType();
     setCurrentBotType(selectedBotType);
     setSelectedBotType(null);
   };
@@ -106,4 +126,10 @@ const SlackIntegration = () => {
   );
 };
 
-export default SlackIntegration;
+const SlackIntegrationWrapper = withUnstatedContainers(SlackIntegration, [AppContainer]);
+
+SlackIntegration.propTypes = {
+  appContainer: PropTypes.instanceOf(AppContainer).isRequired,
+};
+
+export default SlackIntegrationWrapper;