OfficialBotSettings.jsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import React, {
  2. useState, useEffect, useCallback,
  3. } from 'react';
  4. import PropTypes from 'prop-types';
  5. import loggerFactory from '@alias/logger';
  6. import { useTranslation } from 'react-i18next';
  7. import AppContainer from '../../../services/AppContainer';
  8. import { withUnstatedContainers } from '../../UnstatedUtils';
  9. import { toastSuccess, toastError } from '../../../util/apiNotification';
  10. import CustomBotWithProxyIntegrationCard from './CustomBotWithProxyIntegrationCard';
  11. import WithProxyAccordions from './WithProxyAccordions';
  12. const logger = loggerFactory('growi:SlackBotSettings');
  13. const OfficialBotSettings = (props) => {
  14. const { appContainer } = props;
  15. const { t } = useTranslation();
  16. const [proxyUri, setProxyUri] = useState(null);
  17. const retrieveProxyUri = useCallback(async() => {
  18. try {
  19. const res = await appContainer.apiv3.get('/slack-integration-settings');
  20. const { proxyUri } = res.data.settings;
  21. setProxyUri(proxyUri);
  22. }
  23. catch (err) {
  24. toastError(err);
  25. logger.error(err);
  26. }
  27. }, [appContainer.apiv3]);
  28. useEffect(() => {
  29. retrieveProxyUri();
  30. }, [retrieveProxyUri]);
  31. const updateProxyUri = async() => {
  32. try {
  33. await appContainer.apiv3.put('/slack-integration-settings/proxy-uri', {
  34. proxyUri,
  35. });
  36. toastSuccess(t('toaster.update_successed', { target: t('Proxy URL') }));
  37. }
  38. catch (err) {
  39. toastError(err);
  40. logger.error(err);
  41. }
  42. };
  43. return (
  44. <>
  45. <h2 className="admin-setting-header">{t('admin:slack_integration.official_bot_integration')}</h2>
  46. {/* TODO delete tmp props */}
  47. <CustomBotWithProxyIntegrationCard
  48. growiApps={
  49. [
  50. { name: 'siteName1', active: true },
  51. { name: 'siteName2', active: false },
  52. { name: 'siteName3', active: false },
  53. ]
  54. }
  55. slackWorkSpaces={
  56. [
  57. { name: 'wsName1', active: true },
  58. { name: 'wsName2', active: false },
  59. ]
  60. }
  61. isSlackScopeSet
  62. />
  63. <div className="form-group row my-4">
  64. <label className="text-left text-md-right col-md-3 col-form-label mt-3">Proxy URL</label>
  65. <div className="col-md-6 mt-3">
  66. <input
  67. className="form-control"
  68. type="text"
  69. name="settingForm[proxyUrl]"
  70. defaultValue={proxyUri}
  71. onChange={(e) => { setProxyUri(e.target.value) }}
  72. />
  73. </div>
  74. <div className="col-md-2 mt-3 text-center text-md-left">
  75. <button type="button" className="btn btn-primary" onClick={updateProxyUri}>{ t('Update') }</button>
  76. </div>
  77. </div>
  78. <h2 className="admin-setting-header">{t('admin:slack_integration.official_bot_settings')}</h2>
  79. <div className="my-5 mx-3">
  80. <WithProxyAccordions botType="officialBot" />
  81. </div>
  82. </>
  83. );
  84. };
  85. const OfficialBotSettingsWrapper = withUnstatedContainers(OfficialBotSettings, [AppContainer]);
  86. OfficialBotSettings.propTypes = {
  87. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  88. };
  89. export default OfficialBotSettingsWrapper;