actionRootCats.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { mock, query } from '../helpers';
  2. import { actionPromise } from '../reducers';
  3. export const actionRootCats = () => async (dispatch, getState) => {
  4. dispatch(
  5. actionPromise(
  6. 'rootCats',
  7. new Promise((resolve) => {
  8. setTimeout(
  9. Math.random() > 0.01
  10. ? resolve({
  11. data: [
  12. {
  13. id: 1,
  14. name: 'Categoty 1',
  15. },
  16. {
  17. id: 2,
  18. name: 'Categoty 2',
  19. },
  20. {
  21. id: 3,
  22. name: 'Categoty 3',
  23. },
  24. {
  25. id: 4,
  26. name: 'Categoty 4',
  27. },
  28. ],
  29. })
  30. : resolve({
  31. errors: [{ message: 'Error adsasdadas' }],
  32. }),
  33. 400
  34. );
  35. })
  36. // .then((res) => res.json())
  37. .then((data) => {
  38. console.log(data);
  39. if (data.errors) {
  40. throw new Error(JSON.stringify(data.errors));
  41. } else return data.data;
  42. })
  43. )
  44. );
  45. };
  46. // () => ({
  47. // data: [
  48. // {
  49. // id: 1,
  50. // name: 'Categoty 1',
  51. // },
  52. // {
  53. // id: 2,
  54. // name: 'Categoty 2',
  55. // },
  56. // {
  57. // id: 3,
  58. // name: 'Categoty 3',
  59. // },
  60. // {
  61. // id: 4,
  62. // name: 'Categoty 4',
  63. // },
  64. // ],
  65. // }),
  66. // .then((data) => {
  67. // if (data.errors) {
  68. // throw new Error(JSON.stringify(data.errors));
  69. // } else return Object.values(data.data)[0];
  70. // })
  71. // fetch(backendURL + "/api/reception/patient/", {
  72. // method: "GET",
  73. // headers: {
  74. // "Content-Type": "application/json",
  75. // ...(localStorage.authToken ? { Authorization: "Bearer " + localStorage.authToken } : {}),
  76. // },
  77. // });
  78. // actionPromise("patientAll", fetch(url, {
  79. // type:"GET",
  80. // headers: {
  81. // "Content-Type": "application/json",
  82. // ...(localStorage.authToken ? { Authorization: "Bearer " + localStorage.authToken } : {}),
  83. // },
  84. // body: data,
  85. // })
  86. // .then((res) => res.json())
  87. // .then((data) => {
  88. // if (typeof data === "string") {
  89. // throw new Error(data);
  90. // } else return Object.values(data);
  91. // }))