appNotification.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { AppNotification, AppNotificationSeverity, AppNotificationTimeout } from 'app/types';
  2. import { getMessageFromError } from 'app/core/utils/errors';
  3. const defaultSuccessNotification: AppNotification = {
  4. title: '',
  5. text: '',
  6. severity: AppNotificationSeverity.Success,
  7. icon: 'fa fa-check',
  8. timeout: AppNotificationTimeout.Success,
  9. };
  10. const defaultWarningNotification: AppNotification = {
  11. title: '',
  12. text: '',
  13. severity: AppNotificationSeverity.Warning,
  14. icon: 'fa fa-exclamation',
  15. timeout: AppNotificationTimeout.Warning,
  16. };
  17. const defaultErrorNotification: AppNotification = {
  18. title: '',
  19. text: '',
  20. severity: AppNotificationSeverity.Error,
  21. icon: 'fa fa-exclamation-triangle',
  22. timeout: AppNotificationTimeout.Error,
  23. };
  24. export const createSuccessNotification = (title: string, text?: string): AppNotification => ({
  25. ...defaultSuccessNotification,
  26. title: title,
  27. text: text,
  28. id: Date.now(),
  29. });
  30. export const createErrorNotification = (title: string, text?: any): AppNotification => {
  31. return {
  32. ...defaultErrorNotification,
  33. title: title,
  34. text: getMessageFromError(text),
  35. id: Date.now(),
  36. };
  37. };
  38. export const createWarningNotification = (title: string, text?: string): AppNotification => ({
  39. ...defaultWarningNotification,
  40. title: title,
  41. text: text,
  42. id: Date.now(),
  43. });