registrationEvent.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import * as types from "../actionTypes/actionTypes";
  2. const urlRegEvent = 'https://api-marathon.herokuapp.com/api/v1/eventUsers';
  3. //get
  4. export const getRegEvent = payload => ({
  5. type: types.GET_REGISTRATION_EVENT,
  6. payload
  7. });
  8. export const getRegEventSuccess = payload => ({
  9. type: types.GET_REGISTRATION_EVENT_SUCCESS,
  10. payload
  11. });
  12. export const getRegEventError = payload => ({
  13. type: types.GET_REGISTRATION_EVENT_ERROR,
  14. payload
  15. });
  16. export const getAllRegEvent = () => {
  17. return dispatch => {
  18. let promise = fetch(urlRegEvent)
  19. dispatch(getRegEvent())
  20. promise.then(
  21. data => data.json().then(data => dispatch(getRegEventSuccess(data))),
  22. error => dispatch(getRegEventError(error))
  23. )
  24. }
  25. }
  26. //post
  27. export const regEvent = payload => ({
  28. type: types.POST_REGISTRATION_EVENT,
  29. payload
  30. });
  31. export const regEventSuccess = payload => ({
  32. type: types.POST_REGISTRATION_EVENT_SUCCESS,
  33. payload
  34. });
  35. export const regEventError = payload => ({
  36. type: types.POST_REGISTRATION_EVENT_ERROR,
  37. payload
  38. });
  39. export const regEventSubmit = payload => {
  40. console.log('post');
  41. return dispatch => {
  42. let promise = fetch(urlRegEvent,
  43. {
  44. method: 'POST',
  45. body: JSON.stringify(payload),
  46. headers: {
  47. "Content-type": "application/json"
  48. }
  49. }
  50. )
  51. dispatch(regEvent())
  52. promise.then(
  53. data => data.json().then(data => dispatch(regEventSuccess(data))),
  54. error => dispatch(regEventError(error))
  55. )
  56. }
  57. }
  58. //put
  59. /*export const putRegEvent = payload => ({
  60. type: types.PUT_REGISTRATION_EVENT,
  61. payload
  62. });
  63. export const putRegEventSuccess = payload => ({
  64. type: types.PUT_REGISTRATION_EVENT_SUCCESS,
  65. payload
  66. });
  67. export const putRegEventError = payload => ({
  68. type: types.PUT_REGISTRATION_EVENT_ERROR,
  69. payload
  70. });*/
  71. //передать обьект с id юзера и обьект event
  72. /*export const putRegEventSubmit = payload => {
  73. console.log('action',payload.value);
  74. return dispatch => {
  75. let promise = fetch(`${urlRegEvent}/${payload.id}`,
  76. {
  77. method: 'PUT',
  78. body: JSON.stringify(payload.value),
  79. headers: {
  80. "Content-type": "application/json"
  81. }
  82. }
  83. )
  84. dispatch(putRegEvent())
  85. promise.then(
  86. data => data.json().then(data => dispatch(putRegEventSuccess(data))),
  87. error => dispatch(putRegEventError(error))
  88. )
  89. }
  90. }*/