SlackConfiguration.jsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import React from 'react';
  2. import { useTranslation } from 'next-i18next';
  3. import PropTypes from 'prop-types';
  4. import AdminSlackIntegrationLegacyContainer from '~/client/services/AdminSlackIntegrationLegacyContainer';
  5. import { toastSuccess, toastError } from '~/client/util/toastr';
  6. import loggerFactory from '~/utils/logger';
  7. import { withUnstatedContainers } from '../../UnstatedUtils';
  8. import AdminUpdateButtonRow from '../Common/AdminUpdateButtonRow';
  9. const logger = loggerFactory('growi:slackAppConfiguration');
  10. class SlackConfiguration extends React.Component {
  11. constructor(props) {
  12. super(props);
  13. this.onClickSubmit = this.onClickSubmit.bind(this);
  14. }
  15. async onClickSubmit() {
  16. const { t, adminSlackIntegrationLegacyContainer } = this.props;
  17. try {
  18. await adminSlackIntegrationLegacyContainer.updateSlackAppConfiguration();
  19. toastSuccess(t('notification_settings.updated_slackApp'));
  20. }
  21. catch (err) {
  22. toastError(err);
  23. logger.error(err);
  24. }
  25. }
  26. render() {
  27. const { t, adminSlackIntegrationLegacyContainer } = this.props;
  28. return (
  29. <React.Fragment>
  30. <div className="row my-3">
  31. <div className="col-6 text-start">
  32. <div className="dropdown">
  33. <button
  34. className="btn btn-secondary dropdown-toggle"
  35. type="button"
  36. id="dropdownMenuButton"
  37. data-bs-toggle="dropdown"
  38. aria-haspopup="true"
  39. aria-expanded="true"
  40. >
  41. {`Slack ${adminSlackIntegrationLegacyContainer.state.selectSlackOption}`}
  42. </button>
  43. <div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
  44. <button className="dropdown-item" type="button" onClick={() => adminSlackIntegrationLegacyContainer.switchSlackOption('Incoming Webhooks')}>
  45. Slack Incoming Webhooks
  46. </button>
  47. <button className="dropdown-item" type="button" onClick={() => adminSlackIntegrationLegacyContainer.switchSlackOption('App')}>Slack App</button>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. {adminSlackIntegrationLegacyContainer.state.selectSlackOption === 'Incoming Webhooks' ? (
  53. <React.Fragment>
  54. <h2 className="border-bottom mb-5">{t('notification_settings.slack_incoming_configuration')}</h2>
  55. <div className="row mb-3">
  56. <label className="form-label col-md-3 text-start text-md-end">Webhook URL</label>
  57. <div className="col-md-6">
  58. <input
  59. className="form-control"
  60. type="text"
  61. value={adminSlackIntegrationLegacyContainer.state.webhookUrl || ''}
  62. onChange={e => adminSlackIntegrationLegacyContainer.changeWebhookUrl(e.target.value)}
  63. />
  64. </div>
  65. </div>
  66. <div className="row mb-3">
  67. <div className="offset-md-3 col-md-6 text-start">
  68. <div className="form-check form-check-success">
  69. <input
  70. type="checkbox"
  71. className="form-check-input"
  72. id="cbPrioritizeIWH"
  73. checked={adminSlackIntegrationLegacyContainer.state.isIncomingWebhookPrioritized || false}
  74. onChange={() => { adminSlackIntegrationLegacyContainer.switchIsIncomingWebhookPrioritized() }}
  75. />
  76. <label className="form-label form-check-label" htmlFor="cbPrioritizeIWH">
  77. {t('notification_settings.prioritize_webhook')}
  78. </label>
  79. </div>
  80. <p className="form-text text-muted">
  81. {t('notification_settings.prioritize_webhook_desc')}
  82. </p>
  83. </div>
  84. </div>
  85. </React.Fragment>
  86. )
  87. : (
  88. <React.Fragment>
  89. <h2 className="border-bottom mb-3">{t('notification_settings.slack_app_configuration')}</h2>
  90. <div className="card custom-card bg-danger-subtle">
  91. <span className="text-danger"><span className="material-symbols-outlined">error</span>NOT RECOMMENDED</span>
  92. <br />
  93. {/* eslint-disable-next-line react/no-danger */}
  94. <span dangerouslySetInnerHTML={{ __html: t('notification_settings.slack_app_configuration_desc') }} />
  95. <br />
  96. <a
  97. href="#slack-incoming-webhooks"
  98. data-bs-toggle="tab"
  99. onClick={() => adminSlackIntegrationLegacyContainer.switchSlackOption('Incoming Webhooks')}
  100. >
  101. {t('notification_settings.use_instead')}
  102. </a>
  103. </div>
  104. <div className="row mb-5 mt-4">
  105. <label className="form-label col-md-3 text-start text-md-end">OAuth access token</label>
  106. <div className="col-md-6">
  107. <input
  108. className="form-control"
  109. type="text"
  110. value={adminSlackIntegrationLegacyContainer.state.slackToken || ''}
  111. onChange={e => adminSlackIntegrationLegacyContainer.changeSlackToken(e.target.value)}
  112. />
  113. </div>
  114. </div>
  115. </React.Fragment>
  116. )
  117. }
  118. <AdminUpdateButtonRow
  119. onClick={this.onClickSubmit}
  120. disabled={adminSlackIntegrationLegacyContainer.state.retrieveError != null}
  121. />
  122. <hr />
  123. <h3>
  124. <span className="material-symbols-outlined" aria-hidden="true">help</span>{' '}
  125. <a href="#collapseHelpForIwh" data-bs-toggle="collapse">{t('notification_settings.how_to.header')}</a>
  126. </h3>
  127. <ol id="collapseHelpForIwh" className="collapse card custom-card bg-body-tertiary">
  128. <li className="ms-3">
  129. {t('notification_settings.how_to.workspace')}
  130. <ol>
  131. {/* eslint-disable-next-line react/no-danger */}
  132. <li dangerouslySetInnerHTML={{ __html: t('notification_settings.how_to.workspace_desc1') }} />
  133. <li>{t('notification_settings.how_to.workspace_desc2')}</li>
  134. <li>{t('notification_settings.how_to.workspace_desc3')}</li>
  135. </ol>
  136. </li>
  137. <li className="ms-3">
  138. {t('notification_settings.how_to.at_growi')}
  139. <ol>
  140. {/* eslint-disable-next-line react/no-danger */}
  141. <li dangerouslySetInnerHTML={{ __html: t('notification_settings.how_to.at_growi_desc') }} />
  142. </ol>
  143. </li>
  144. </ol>
  145. </React.Fragment>
  146. );
  147. }
  148. }
  149. SlackConfiguration.propTypes = {
  150. t: PropTypes.func.isRequired, // i18next
  151. adminSlackIntegrationLegacyContainer: PropTypes.instanceOf(AdminSlackIntegrationLegacyContainer).isRequired,
  152. };
  153. const SlackConfigurationWrapperFc = (props) => {
  154. const { t } = useTranslation('admin');
  155. return <SlackConfiguration t={t} {...props} />;
  156. };
  157. const SlackConfigurationWrapper = withUnstatedContainers(SlackConfigurationWrapperFc, [AdminSlackIntegrationLegacyContainer]);
  158. export default SlackConfigurationWrapper;