You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // @flow
  2. import {
  3. CLEAR_NOTIFICATIONS,
  4. HIDE_NOTIFICATION,
  5. SET_NOTIFICATIONS_ENABLED,
  6. SHOW_NOTIFICATION
  7. } from './actionTypes';
  8. import { NOTIFICATION_TYPE } from './constants';
  9. /**
  10. * Clears (removes) all the notifications.
  11. *
  12. * @returns {{
  13. * type: CLEAR_NOTIFICATIONS
  14. * }}
  15. */
  16. export function clearNotifications() {
  17. return {
  18. type: CLEAR_NOTIFICATIONS
  19. };
  20. }
  21. /**
  22. * Removes the notification with the passed in id.
  23. *
  24. * @param {string} uid - The unique identifier for the notification to be
  25. * removed.
  26. * @returns {{
  27. * type: HIDE_NOTIFICATION,
  28. * uid: number
  29. * }}
  30. */
  31. export function hideNotification(uid: number) {
  32. return {
  33. type: HIDE_NOTIFICATION,
  34. uid
  35. };
  36. }
  37. /**
  38. * Stops notifications from being displayed.
  39. *
  40. * @param {boolean} enabled - Whether or not notifications should display.
  41. * @returns {{
  42. * type: SET_NOTIFICATIONS_ENABLED,
  43. * enabled: boolean
  44. * }}
  45. */
  46. export function setNotificationsEnabled(enabled: boolean) {
  47. return {
  48. type: SET_NOTIFICATIONS_ENABLED,
  49. enabled
  50. };
  51. }
  52. /**
  53. * Queues an error notification for display.
  54. *
  55. * @param {Object} props - The props needed to show the notification component.
  56. * @returns {Object}
  57. */
  58. export function showErrorNotification(props: Object) {
  59. return showNotification({
  60. ...props,
  61. appearance: NOTIFICATION_TYPE.ERROR
  62. });
  63. }
  64. /**
  65. * Queues a notification for display.
  66. *
  67. * @param {Object} props - The props needed to show the notification component.
  68. * @param {number} timeout - How long the notification should display before
  69. * automatically being hidden.
  70. * @returns {{
  71. * type: SHOW_NOTIFICATION,
  72. * props: Object,
  73. * timeout: number,
  74. * uid: number
  75. * }}
  76. */
  77. export function showNotification(props: Object = {}, timeout: ?number) {
  78. return {
  79. type: SHOW_NOTIFICATION,
  80. props,
  81. timeout,
  82. uid: window.Date.now()
  83. };
  84. }
  85. /**
  86. * Queues a warning notification for display.
  87. *
  88. * @param {Object} props - The props needed to show the notification component.
  89. * @returns {Object}
  90. */
  91. export function showWarningNotification(props: Object) {
  92. return showNotification({
  93. ...props,
  94. appearance: NOTIFICATION_TYPE.WARNING
  95. });
  96. }