AdminNotificationContainer.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { Container } from 'unstated';
  2. /**
  3. * Service container for admin Notification setting page (NotificationSetting.jsx)
  4. * @extends {Container} unstated Container
  5. */
  6. export default class AdminNotificationContainer extends Container {
  7. constructor(appContainer) {
  8. super();
  9. this.appContainer = appContainer;
  10. this.state = {
  11. retrieveError: null,
  12. selectSlackOption: 'Incoming Webhooks',
  13. webhookUrl: '',
  14. isIncomingWebhookPrioritized: false,
  15. slackToken: '',
  16. userNotifications: [],
  17. grobalNotifications: [],
  18. };
  19. }
  20. /**
  21. * Workaround for the mangling in production build to break constructor.name
  22. */
  23. static getClassName() {
  24. return 'AdminNotificationContainer';
  25. }
  26. /**
  27. * Retrieve notificationData
  28. */
  29. retrieveNotificationData() {
  30. // TODO GW-821 retrive data from api
  31. }
  32. /**
  33. * Switch slackOption
  34. */
  35. switchSlackOption(slackOption) {
  36. this.setState({ selectSlackOption: slackOption });
  37. }
  38. /**
  39. * Change webhookUrl
  40. */
  41. changeWebhookUrl(webhookUrl) {
  42. this.setState({ webhookUrl });
  43. }
  44. /**
  45. * Switch incomingWebhookPrioritized
  46. */
  47. switchIsIncomingWebhookPrioritized() {
  48. this.setState({ isIncomingWebhookPrioritized: !this.state.isIncomingWebhookPrioritized });
  49. }
  50. /**
  51. * Change slackToken
  52. */
  53. changeSlackToken(slackToken) {
  54. this.setState({ slackToken });
  55. }
  56. /**
  57. * Update slackAppConfiguration
  58. * @memberOf SlackAppConfiguration
  59. */
  60. async updateSlackAppConfiguration() {
  61. const response = await this.appContainer.apiv3.put('/notification-setting/slack-configuration', {
  62. webhookUrl: this.state.webhookUrl,
  63. isIncomingWebhookPrioritized: this.state.isIncomingWebhookPrioritized,
  64. slackToken: this.state.slackToken,
  65. });
  66. return response;
  67. }
  68. /**
  69. * Add notificationPattern
  70. * @memberOf SlackAppConfiguration
  71. */
  72. async addNotificationPattern(pathPattern, channel) {
  73. return this.appContainer.apiv3.post('/notification-setting/user-notification', {
  74. pathPattern,
  75. channel,
  76. });
  77. }
  78. }