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

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