SlackNotification.jsx 2.7 KB

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