SlackConfiguration.jsx 7.0 KB

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