SlackNotification.jsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. /**
  5. *
  6. * @author Yuki Takei <yuki@weseek.co.jp>
  7. *
  8. * @export
  9. * @class SlackNotification
  10. * @extends {React.Component}
  11. */
  12. class SlackNotification extends React.Component {
  13. constructor(props) {
  14. super(props);
  15. this.updateCheckboxHandler = this.updateCheckboxHandler.bind(this);
  16. this.updateSlackChannelsHandler = this.updateSlackChannelsHandler.bind(this);
  17. }
  18. updateCheckboxHandler(event) {
  19. const value = event.target.checked;
  20. if (this.props.onEnabledFlagChange != null) {
  21. this.props.onEnabledFlagChange(value);
  22. }
  23. }
  24. updateSlackChannelsHandler(event) {
  25. const value = event.target.value;
  26. if (this.props.onChannelChange != null) {
  27. this.props.onChannelChange(value);
  28. }
  29. }
  30. render() {
  31. const { t } = this.props;
  32. return (
  33. <div className="grw-slack-notification">
  34. <div className="input-group extended-setting">
  35. <label className="input-group-addon">
  36. <div className="custom-control custom-switch custom-switch-lg custom-switch-slack">
  37. <input
  38. type="checkbox"
  39. className="custom-control-input border-0"
  40. id={this.props.id}
  41. checked={this.props.isSlackEnabled}
  42. onChange={this.updateCheckboxHandler}
  43. />
  44. <label className="custom-control-label" htmlFor={this.props.id}>
  45. </label>
  46. </div>
  47. </label>
  48. <input
  49. className="form-control"
  50. type="text"
  51. value={this.props.slackChannels}
  52. placeholder="Input channels"
  53. data-toggle="popover"
  54. title={t('slack_notification.popover_title')}
  55. data-content={t('slack_notification.popover_desc')}
  56. data-trigger="focus"
  57. data-placement="top"
  58. onChange={this.updateSlackChannelsHandler}
  59. />
  60. </div>
  61. </div>
  62. );
  63. }
  64. }
  65. SlackNotification.propTypes = {
  66. t: PropTypes.func.isRequired, // i18next
  67. isSlackEnabled: PropTypes.bool.isRequired,
  68. slackChannels: PropTypes.string.isRequired,
  69. onEnabledFlagChange: PropTypes.func,
  70. onChannelChange: PropTypes.func,
  71. id: PropTypes.string.isRequired,
  72. };
  73. export default withTranslation()(SlackNotification);