SlackIntegration.jsx 3.6 KB

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