shedule.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import * as types from '../actionsTypes/actionsTypes'
  2. import {getDoctors} from "./actions";
  3. const URL = "https://api-clinics.herokuapp.com/api/v1/";
  4. export const setSheduleDoctor = payload => ({
  5. type: types.CHANGE_SHEDULE_DOCTOR,
  6. payload
  7. });
  8. // -----------------------------------------------------------------------------------------------------------------
  9. const postSheduleRequest = payload => ({
  10. type: types.POST_SHEDULE_REQUEST,
  11. payload
  12. });
  13. // -----------------------------------------------------------------------------------------------------------------
  14. const postSheduleSuccess = payload => ({
  15. type: types.POST_SHEDULE_REQUEST_SUCCESS,
  16. payload
  17. });
  18. // -----------------------------------------------------------------------------------------------------------------
  19. const postSheduleFail = payload => ({
  20. type: types.POST_SHEDULE_REQUEST_FAIL,
  21. payload
  22. });
  23. // -----------------------------------------------------------------------------------------------------------------
  24. export const postShedule = (payload) => dispatch => {
  25. dispatch(postSheduleRequest());
  26. return fetch(`${URL}shedule`, {
  27. method: "POST",
  28. credentials:"include",
  29. headers: {
  30. 'Content-Type': 'application/json'
  31. },
  32. body: JSON.stringify(payload)
  33. })
  34. .then(res => res.json())
  35. .then(res => dispatch(postSheduleSuccess(res))).then(dispatch(getDoctors()))
  36. .catch(err => dispatch(postSheduleFail(err)));
  37. };