SlackNotification.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. /**
  4. *
  5. * @author Yuki Takei <yuki@weseek.co.jp>
  6. *
  7. * @export
  8. * @class SlackNotification
  9. * @extends {React.Component}
  10. */
  11. export default class SlackNotification extends React.Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. isNotification: false,
  16. notifSlackChannel: '',
  17. };
  18. this.init = this.init.bind(this);
  19. this.updateState = this.updateState.bind(this);
  20. this.updateStateCheckbox = this.updateStateCheckbox.bind(this);
  21. }
  22. componentWillMount() {
  23. const pageId = this.props.pageId;
  24. if (pageId) {
  25. this.init();
  26. }
  27. this.retrieveData = this.retrieveData.bind(this);
  28. }
  29. init() {
  30. if (!this.props.pageId) {
  31. return ;
  32. }
  33. this.retrieveData();
  34. }
  35. /**
  36. * Load data of comments and store them in state
  37. */
  38. retrieveData() {
  39. // get data (desc order array)
  40. this.props.crowi.apiGet('/pages.updatePost', {path: this.props.pagePath})
  41. .then(res => {
  42. if (res.ok) {
  43. this.setState({notifSlackChannel: res.updatePost.join(',')});
  44. }
  45. });
  46. }
  47. updateState(value) {
  48. this.setState({notifSlackChannel: value})
  49. }
  50. updateStateCheckbox(event) {
  51. const value = event.target.checked;
  52. this.setState({isNotification: value})
  53. }
  54. render() {
  55. return (
  56. <div className="form-inline d-flex align-items-center" id="comment-form-setting">
  57. <span className="input-group input-group-sm input-group-slack extended-setting m-r-5">
  58. <label className="input-group-addon">
  59. <img id="slack-mark-white" src="/images/icons/slack/mark-monochrome_white.svg" width="18" height="18"/>
  60. <img id="slack-mark-black" src="/images/icons/slack/mark-monochrome_black.svg" width="18" height="18"/>
  61. <input className="comment-form-slack" type="checkbox" name="slack" value="1" onChange={this.updateStateCheckbox}/>
  62. </label>
  63. <input className="form-control" type="text" value={this.state.notifSlackChannel} placeholder="slack-channel-name"
  64. id="comment-form-slack-channel"
  65. data-toggle="popover"
  66. title="Slack通知"
  67. data-content="通知するにはチェックを入れてください。カンマ区切りで複数チャンネルに通知することができます。"
  68. data-trigger="focus"
  69. data-placement="top"
  70. onChange={e => this.updateState(e.target.value)}
  71. />
  72. </span>
  73. </div>
  74. );
  75. }
  76. }
  77. SlackNotification.propTypes = {
  78. crowi: PropTypes.object.isRequired,
  79. pageId: PropTypes.string,
  80. pagePath: PropTypes.string,
  81. };