Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

actions.js 1.9KB

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