apiNotification.js 890 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // show API error/sucess toastr
  2. import * as toastr from 'toastr';
  3. import toArrayIfNot from '../../../lib/util/toArrayIfNot';
  4. const toastrOption = {
  5. error: {
  6. closeButton: true,
  7. progressBar: true,
  8. newestOnTop: false,
  9. showDuration: '100',
  10. hideDuration: '100',
  11. timeOut: '3000',
  12. },
  13. success: {
  14. closeButton: true,
  15. progressBar: true,
  16. newestOnTop: false,
  17. showDuration: '100',
  18. hideDuration: '100',
  19. timeOut: '3000',
  20. },
  21. };
  22. // accepts both a single error and an array of errors
  23. export const toastError = (err, header = 'Error', option = toastrOption.error) => {
  24. const errs = toArrayIfNot(err);
  25. for (const err of errs) {
  26. toastr.error(err.message, header, option);
  27. }
  28. };
  29. // only accepts a single item
  30. export const toastSuccess = (body, header = 'Success', option = toastrOption.success) => {
  31. toastr.success(body, header, option);
  32. };