SlackIntegration.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 handleBotTypeSelect = (clickedBotType) => {
  11. if (clickedBotType === currentBotType) {
  12. return;
  13. }
  14. if (currentBotType === null) {
  15. setCurrentBotType(clickedBotType);
  16. return;
  17. }
  18. setSelectedBotType(clickedBotType);
  19. };
  20. const handleCancelBotChange = () => {
  21. setSelectedBotType(null);
  22. };
  23. const changeCurrentBotSettings = () => {
  24. setCurrentBotType(selectedBotType);
  25. setSelectedBotType(null);
  26. };
  27. let settingsComponent = null;
  28. switch (currentBotType) {
  29. case 'official-bot':
  30. settingsComponent = <OfficialBotSettings />;
  31. break;
  32. case 'custom-bot-without-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. isOpen={selectedBotType != null}
  44. onConfirmClick={changeCurrentBotSettings}
  45. onCancelClick={handleCancelBotChange}
  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
  57. className={`card admin-bot-card mx-3 py-5 rounded ${currentBotType === 'official-bot' ? 'border-info' : ''}`}
  58. onClick={() => handleBotTypeSelect('official-bot')}
  59. >
  60. <div className="card-body">
  61. <h5 className="card-title">Official Bot</h5>
  62. <p className="card-text">This is a wider card with supporting text below as a natural lead-in to additional content.</p>
  63. </div>
  64. </div>
  65. <div
  66. className={`card admin-bot-card mx-3 py-5 rounded ${currentBotType === 'custom-bot-without-proxy' ? 'border-info' : ''}`}
  67. onClick={() => handleBotTypeSelect('custom-bot-without-proxy')}
  68. >
  69. <div className="card-body">
  70. <h5 className="card-title">Custom Bot (Without Proxy)</h5>
  71. <p className="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. </p>
  72. </div>
  73. </div>
  74. <div
  75. className={`card admin-bot-card mx-3 py-5 rounded ${currentBotType === 'custom-bot-with-proxy' ? 'border-info' : ''}`}
  76. onClick={() => handleBotTypeSelect('custom-bot-with-proxy')}
  77. >
  78. <div className="card-body">
  79. <h5 className="card-title">Custom Bot (With Proxy)</h5>
  80. <p className="card-text">This is a wider card with supporting text below as a natural lead-in to additional content.</p>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. {settingsComponent}
  86. </>
  87. );
  88. };
  89. export default SlackIntegration;