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

Added modal for changing bot settings

Steven Fukase 5 лет назад
Родитель
Сommit
c452a66ad9

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

@@ -1,7 +1,9 @@
 import React, { useRef, useEffect } from 'react';
 import React, { useRef, useEffect } from 'react';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
+// import { useTranslation } from 'react-i18next';
 
 
 const ConfirmBotChangeModal = ({ show, onButtonClick }) => {
 const ConfirmBotChangeModal = ({ show, onButtonClick }) => {
+  // const { t } = useTranslation();
   const dialog = useRef({});
   const dialog = useRef({});
   useEffect(() => {
   useEffect(() => {
     $(dialog.current).modal(show ? 'show' : 'hide');
     $(dialog.current).modal(show ? 'show' : 'hide');

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

@@ -7,20 +7,28 @@ import CustomBotWithProxySettings from './CustomBotWithProxySettings';
 import ConfirmBotChangeModal from './ConfirmBotChangeModal';
 import ConfirmBotChangeModal from './ConfirmBotChangeModal';
 
 
 const SlackIntegration = () => {
 const SlackIntegration = () => {
-
+  const [currentBotType, setcurrentBotType] = useState(null);
+  const [selectedBotType, setSelectedBotType] = useState(null);
   const [modalVisibility, setmodalVisibility] = useState(false);
   const [modalVisibility, setmodalVisibility] = useState(false);
-  const [currentBotType, setcurrentBotType] = useState('custom-bot-non-proxy');
-  let settingsComponent = null;
-
-  const changeBotSettings = (botType) => {
-    console.log(botType);
-  }
 
 
   const handleBotTypeSelect = (clickedBotType) => {
   const handleBotTypeSelect = (clickedBotType) => {
-    console.log(clickedBotType);
+    setSelectedBotType(clickedBotType);
     setmodalVisibility(true);
     setmodalVisibility(true);
   };
   };
 
 
+  const handleBotChangeCancel = () => {
+    setSelectedBotType(null);
+    setmodalVisibility(false);
+  };
+
+  const changeCurrentBotSettings = () => {
+    setcurrentBotType(selectedBotType);
+    setSelectedBotType(null);
+    setmodalVisibility(false);
+  };
+
+  let settingsComponent = null;
+
   switch (currentBotType) {
   switch (currentBotType) {
     case 'official-bot':
     case 'official-bot':
       settingsComponent = <OfficialBotSettings />;
       settingsComponent = <OfficialBotSettings />;
@@ -31,9 +39,6 @@ const SlackIntegration = () => {
     case 'custom-bot-with-proxy':
     case 'custom-bot-with-proxy':
       settingsComponent = <CustomBotWithProxySettings />;
       settingsComponent = <CustomBotWithProxySettings />;
       break;
       break;
-    default:
-      settingsComponent = <OfficialBotSettings />;
-      break;
   }
   }
 
 
   return (
   return (
@@ -42,8 +47,8 @@ const SlackIntegration = () => {
         <ConfirmBotChangeModal
         <ConfirmBotChangeModal
           show={modalVisibility}
           show={modalVisibility}
           onButtonClick={(button) => {
           onButtonClick={(button) => {
-            if (button === 'close') setmodalVisibility(false);
-            if (button === 'change') changeBotSettings();
+            if (button === 'close') handleBotChangeCancel();
+            if (button === 'change') changeCurrentBotSettings();
           }}
           }}
         />
         />
       </div>
       </div>
@@ -61,7 +66,7 @@ const SlackIntegration = () => {
           <div className={`card mx-3 py-5 rounded ${currentBotType === 'official-bot' ? 'border-info' : ''}`}>
           <div className={`card mx-3 py-5 rounded ${currentBotType === 'official-bot' ? 'border-info' : ''}`}>
             <div className="card-body">
             <div className="card-body">
               <h5 className="card-title">Official Bot</h5>
               <h5 className="card-title">Official Bot</h5>
-              <p className="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+              <p className="card-text">This is a wider card with supporting text below as a natural lead-in to additional content.</p>
               <a href="#" className="stretched-link" onClick={() => handleBotTypeSelect('official-bot')} />
               <a href="#" className="stretched-link" onClick={() => handleBotTypeSelect('official-bot')} />
             </div>
             </div>
           </div>
           </div>
@@ -77,7 +82,7 @@ const SlackIntegration = () => {
           <div className={`card mx-3 py-5 rounded ${currentBotType === 'custom-bot-with-proxy' ? 'border-info' : ''}`}>
           <div className={`card mx-3 py-5 rounded ${currentBotType === 'custom-bot-with-proxy' ? 'border-info' : ''}`}>
             <div className="card-body">
             <div className="card-body">
               <h5 className="card-title">Custom Bot (With Proxy)</h5>
               <h5 className="card-title">Custom Bot (With Proxy)</h5>
-              <p className="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longerThis is a wider card with supporting text below as a natural lead-This is a wider card with supporting text below as a natural lead-This is a wider card with supporting text below as a natural lead-This is a wider card with supporting text below as a natural lead-</p>
+              <p className="card-text">This is a wider card with supporting text below as a natural lead-in to additional content.</p>
               <a href="#" className="stretched-link" onClick={() => handleBotTypeSelect('custom-bot-with-proxy')} />
               <a href="#" className="stretched-link" onClick={() => handleBotTypeSelect('custom-bot-with-proxy')} />
             </div>
             </div>
           </div>
           </div>