SlackIntegration.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import React, { useState } from 'react';
  2. import AccessTokenSettings from './AccessTokenSettings';
  3. import OfficialBotSettings from './OfficialBotSettings';
  4. import CustomBotWithoutProxySettings from './CustomBotWithoutProxySettings';
  5. import CustomBotWithProxySettings from './CustomBotWithProxySettings';
  6. import ConfirmBotChangeModal from './ConfirmBotChangeModal';
  7. const SlackIntegration = () => {
  8. const [currentBotType, setcurrentBotType] = useState(null);
  9. const [selectedBotType, setSelectedBotType] = useState(null);
  10. const [modalVisibility, setmodalVisibility] = useState(false);
  11. const handleBotTypeSelect = (clickedBotType) => {
  12. if (clickedBotType === currentBotType) {
  13. return;
  14. }
  15. setSelectedBotType(clickedBotType);
  16. setmodalVisibility(true);
  17. };
  18. const handleBotChangeCancel = () => {
  19. setSelectedBotType(null);
  20. setmodalVisibility(false);
  21. };
  22. const changeCurrentBotSettings = () => {
  23. setcurrentBotType(selectedBotType);
  24. setSelectedBotType(null);
  25. setmodalVisibility(false);
  26. };
  27. let settingsComponent = null;
  28. switch (currentBotType) {
  29. case 'official-bot':
  30. settingsComponent = <OfficialBotSettings />;
  31. break;
  32. case 'custom-bot-non-proxy':
  33. settingsComponent = <CustomBotWithoutProxySettings />;
  34. break;
  35. case 'custom-bot-with-proxy':
  36. settingsComponent = <CustomBotWithProxySettings />;
  37. break;
  38. }
  39. return (
  40. <>
  41. <div className="container">
  42. <ConfirmBotChangeModal
  43. show={modalVisibility}
  44. onConfirmClick={changeCurrentBotSettings}
  45. onCancelClick={handleBotChangeCancel}
  46. />
  47. </div>
  48. <div className="row">
  49. <div className="col-lg-12">
  50. <h2 className="admin-setting-header">Access Token</h2>
  51. <AccessTokenSettings />
  52. </div>
  53. </div>
  54. <div className="row my-5">
  55. <div className="card-deck mx-auto">
  56. <div className={`card mx-3 py-5 rounded ${currentBotType === 'official-bot' ? 'border-info' : ''}`}>
  57. <div className="card-body">
  58. <h5 className="card-title">Official Bot</h5>
  59. <p className="card-text">This is a wider card with supporting text below as a natural lead-in to additional content.</p>
  60. <a href="#" className="stretched-link" onClick={() => handleBotTypeSelect('official-bot')} />
  61. </div>
  62. </div>
  63. <div className={`card mx-3 py-5 rounded ${currentBotType === 'custom-bot-non-proxy' ? 'border-info' : ''}`}>
  64. <div className="card-body">
  65. <h5 className="card-title">Custom Bot (Non Proxy)</h5>
  66. <p className="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. </p>
  67. <a href="#" className="stretched-link" onClick={() => handleBotTypeSelect('custom-bot-non-proxy')} />
  68. </div>
  69. </div>
  70. <div className={`card mx-3 py-5 rounded ${currentBotType === 'custom-bot-with-proxy' ? 'border-info' : ''}`}>
  71. <div className="card-body">
  72. <h5 className="card-title">Custom Bot (With Proxy)</h5>
  73. <p className="card-text">This is a wider card with supporting text below as a natural lead-in to additional content.</p>
  74. <a href="#" className="stretched-link" onClick={() => handleBotTypeSelect('custom-bot-with-proxy')} />
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. {settingsComponent}
  80. </>
  81. );
  82. };
  83. export default SlackIntegration;