SlackAppConfiguration.jsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import { createSubscribedElement } from '../../UnstatedUtils';
  5. import AppContainer from '../../../services/AppContainer';
  6. import AdminNotificationContainer from '../../../services/AdminNotificationContainer';
  7. import AdminUpdateButtonRow from '../Common/AdminUpdateButtonRow';
  8. class SlackAppConfiguration extends React.Component {
  9. // TODO GW-788 i18n
  10. render() {
  11. const { adminNotificationContainer } = this.props;
  12. return (
  13. <React.Fragment>
  14. <div className="row mb-5">
  15. <div className="col-xs-6 text-left">
  16. <div className="my-0 btn-group">
  17. <div className="dropdown">
  18. <button className="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  19. <span className="pull-left">Slack {adminNotificationContainer.state.selectSlackOption}</span>
  20. <span className="bs-caret pull-right">
  21. <span className="caret" />
  22. </span>
  23. </button>
  24. {/* TODO adjust dropdown after BS4 */}
  25. <ul className="dropdown-menu" role="menu">
  26. <li type="button" onClick={() => adminNotificationContainer.switchSlackOption('Incoming Webhooks')}>
  27. <a role="menuitem">Slack Incoming Webhooks</a>
  28. </li>
  29. <li type="button" onClick={() => adminNotificationContainer.switchSlackOption('App')}>
  30. <a role="menuitem">Slack App</a>
  31. </li>
  32. </ul>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. {adminNotificationContainer.state.selectSlackOption === 'Incoming Webhooks' ? (
  38. <React.Fragment>
  39. <h2 className="border-bottom mb-5">Slack Incoming Webhooks Configuration</h2>
  40. <div className="row mb-5">
  41. <label className="col-xs-3 text-right">Webhook URL</label>
  42. <div className="col-xs-6">
  43. <input
  44. className="form-control"
  45. type="text"
  46. defaultValue={adminNotificationContainer.state.webhookUrl}
  47. onChange={e => adminNotificationContainer.changeWebhookUrl(e.target.value)}
  48. />
  49. </div>
  50. </div>
  51. <div className="row mb-5">
  52. <div className="col-xs-offset-3 col-xs-6 text-left">
  53. <div className="checkbox checkbox-success">
  54. <input
  55. id="cbPrioritizeIWH"
  56. type="checkbox"
  57. checked={adminNotificationContainer.state.isIncomingWebhookPrioritized}
  58. onChange={() => { adminNotificationContainer.switchIsIncomingWebhookPrioritized() }}
  59. />
  60. <label htmlFor="cbPrioritizeIWH">
  61. Prioritize Incoming Webhook than Slack App
  62. </label>
  63. </div>
  64. <p className="help-block">
  65. Check this option and GROWI use Incoming Webhooks even if Slack App settings are enabled.
  66. </p>
  67. </div>
  68. </div>
  69. </React.Fragment>
  70. )
  71. : (
  72. <React.Fragment>
  73. <h2 className="border-bottom mb-5">Slack App Configuration</h2>
  74. <div className="well">
  75. <i className="icon-fw icon-exclamation text-danger"></i><span className="text-danger">NOT RECOMMENDED</span>
  76. <br /><br />
  77. This is the way that compatible with Crowi,<br />
  78. but not recommended in GROWI because it is <strong>too complex</strong>.
  79. <br /><br />
  80. Please use
  81. <a
  82. href="#slack-incoming-webhooks"
  83. data-toggle="tab"
  84. onClick={() => adminNotificationContainer.switchSlackOption('Incoming Webhooks')}
  85. >
  86. Slack incomming webhooks Configuration
  87. </a>
  88. instead.
  89. </div>
  90. <div className="row mb-5">
  91. <label className="col-xs-3 text-right">OAuth Access Token</label>
  92. <div className="col-xs-6">
  93. <input
  94. className="form-control"
  95. type="text"
  96. defaultValue={adminNotificationContainer.state.slackToken}
  97. onChange={e => adminNotificationContainer.changeSlackToken(e.target.value)}
  98. />
  99. </div>
  100. </div>
  101. </React.Fragment>
  102. )
  103. }
  104. <AdminUpdateButtonRow />
  105. <hr />
  106. <h3>
  107. <i className="icon-question" aria-hidden="true"></i>
  108. <a href="#collapseHelpForIwh" data-toggle="collapse"> How to configure Incoming Webhooks?</a>
  109. </h3>
  110. <ol id="collapseHelpForIwh" className="collapse">
  111. <li>
  112. (At Workspace) Add a hook
  113. <ol>
  114. <li>Go to <a href="https://slack.com/services/new/incoming-webhook">Incoming Webhooks Configuration page</a>.</li>
  115. <li>Choose the default channel to post.</li>
  116. <li>Add.</li>
  117. </ol>
  118. </li>
  119. <li>
  120. (At GROWI admin page) Set Webhook URL
  121. <ol>
  122. <li>Input &rdquo;Webhook URL&rdquo; and submit on this page.</li>
  123. </ol>
  124. </li>
  125. </ol>
  126. </React.Fragment>
  127. );
  128. }
  129. }
  130. const SlackAppConfigurationWrapper = (props) => {
  131. return createSubscribedElement(SlackAppConfiguration, props, [AppContainer, AdminNotificationContainer]);
  132. };
  133. SlackAppConfiguration.propTypes = {
  134. t: PropTypes.func.isRequired, // i18next
  135. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  136. adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired,
  137. };
  138. export default withTranslation()(SlackAppConfigurationWrapper);