actionGoodById.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { mock, query } from '../helpers';
  2. import { actionPromise } from '../reducers';
  3. export const actionGoodById = (_id) => async (dispatch, getState) => {
  4. dispatch(
  5. actionPromise(
  6. 'goodById',
  7. new Promise((resolve) => {
  8. setTimeout(
  9. Math.random() > 0.01
  10. ? resolve({
  11. data: {
  12. id: 6,
  13. name: 'Good 6',
  14. description: 'adaadasda asasd asd asd asd asd ',
  15. price: '999',
  16. images: [
  17. {
  18. url: 'https://content2.rozetka.com.ua/goods/images/big/183546719.jpg',
  19. },
  20. {
  21. url: 'https://content2.rozetka.com.ua/goods/images/big/183546719.jpg',
  22. },
  23. ],
  24. },
  25. })
  26. : resolve({
  27. errors: [{ message: 'Error adsasdadas' }],
  28. }),
  29. 400
  30. );
  31. })
  32. // .then((res) => res.json())
  33. .then((data) => {
  34. console.log(data);
  35. if (data.errors) {
  36. throw new Error(JSON.stringify(data.errors));
  37. } else return data.data;
  38. })
  39. )
  40. );
  41. };