reviews.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import * as types from "../actionTypes/actionTypes";
  2. const reviewsURL = 'https://api-marathon.herokuapp.com/api/v1/feedback';
  3. export const getReviews = payload => ({
  4. type: types.GET_REQUEST_REVIEWS,
  5. payload
  6. });
  7. export const getReviewsSuccess = payload => ({
  8. type: types.GET_REQUEST_SUCCESS_REVIEWS,
  9. payload
  10. });
  11. export const getReviewsError = payload => ({
  12. type: types.GET_REQUEST_ERROR_REVIEWS,
  13. payload
  14. });
  15. export const getAllReviews = (type = 'All events') => {
  16. return dispatch => {
  17. let promise = fetch(type !== 'All events' ? `${reviewsURL}/?event=${type}` : reviewsURL)
  18. dispatch(getReviews())
  19. promise.then(
  20. data => data.json().then(data => dispatch(getReviewsSuccess(data))),
  21. error => dispatch(getReviewsError(error))
  22. )
  23. }
  24. }
  25. export const postReview = payload => ({
  26. type: types.POST_REQUEST_REVIEW,
  27. payload
  28. });
  29. export const postReviewSuccess = payload => ({
  30. type: types.POST_REQUEST_SUCCESS_REVIEW,
  31. payload
  32. });
  33. export const postReviewError = payload => ({
  34. type: types.POST_REQUEST_ERROR_REVIEW,
  35. payload
  36. });
  37. export const postReviewSubmit = payload => {
  38. return dispatch => {
  39. let promise = fetch(reviewsURL,
  40. {
  41. method: 'POST',
  42. body: JSON.stringify(payload),
  43. headers: {
  44. "Content-type": "application/json"
  45. }
  46. }
  47. )
  48. dispatch(postReview())
  49. promise.then(
  50. data => data.json().then(data => dispatch(postReviewSuccess(data))),
  51. error => dispatch(postReviewError(error))
  52. )
  53. }
  54. }