SlackNotification.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. this.props.onChannelChange(value);
  50. }
  51. updateStateCheckbox(event) {
  52. const value = event.target.checked;
  53. this.setState({isNotification: value});
  54. this.props.onSlackOnChange(value);
  55. }
  56. render() {
  57. return (
  58. <div className="form-inline d-flex align-items-center" id="comment-form-setting">
  59. <span className="input-group input-group-sm input-group-slack extended-setting m-r-5">
  60. <label className="input-group-addon">
  61. <img id="slack-mark-white" src="/images/icons/slack/mark-monochrome_white.svg" width="18" height="18"/>
  62. <img id="slack-mark-black" src="/images/icons/slack/mark-monochrome_black.svg" width="18" height="18"/>
  63. <input className="comment-form-slack" type="checkbox" name="slack" value="1" onChange={this.updateStateCheckbox}/>
  64. </label>
  65. <input className="form-control" type="text" value={this.state.notifSlackChannel} placeholder="slack-channel-name"
  66. id="comment-form-slack-channel"
  67. data-toggle="popover"
  68. title="Slack通知"
  69. data-content="通知するにはチェックを入れてください。カンマ区切りで複数チャンネルに通知することができます。"
  70. data-trigger="focus"
  71. data-placement="top"
  72. onChange={e => this.updateState(e.target.value)}
  73. />
  74. </span>
  75. </div>
  76. );
  77. }
  78. }
  79. SlackNotification.propTypes = {
  80. crowi: PropTypes.object.isRequired,
  81. pageId: PropTypes.string,
  82. pagePath: PropTypes.string,
  83. onChannelChange: PropTypes.func.isRequired,
  84. onSlackOnChange: PropTypes.func.isRequired,
  85. };