SlackAppConfiguration.jsx 6.7 KB

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