shedule.js 1.4 KB

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