actions.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. import * as types from '../actionsTypes/actionsTypes'
  2. const URL = "https://api-clinics.herokuapp.com/api/v1/";
  3. // -----------------------------------------------------------------------------------------------------------------
  4. export const changeInputDoctorForm = payload => ({
  5. type: types.CHANGE_INPUT_VALUE_DOCTOR_FORM,
  6. payload
  7. })
  8. // -----------------------------------------------------------------------------------------------------------------
  9. export const changeSelectedDoctor = payload => ({
  10. type: types.CHANGE_SELECTED_DOCTOR,
  11. payload
  12. });
  13. // -----------------------------------------------------------------------------------------------------------------
  14. export const setAppointmentShedule = payload => ({
  15. type: types.CHANGE_APPOINTMENT_SHEDULE,
  16. payload
  17. });
  18. export const setAppointmentDoctor = payload => ({
  19. type: types.CHANGE_APPOINTMENT_DOCTOR,
  20. payload
  21. });
  22. export const setAppointmentTime = payload => ({
  23. type: types.CHANGE_APPOINTMENT_TIME,
  24. payload
  25. });
  26. export const setAppointmentSpec = payload => ({
  27. type: types.CHANGE_APPOINTMENT_SPEC,
  28. payload
  29. });
  30. export const setAppointmentComment = payload => ({
  31. type: types.CHANGE_APPOINTMENT_COMMENT,
  32. payload
  33. });
  34. export const clearAppointment = payload => ({
  35. type: types.CLEAR_APPOINTMENT,
  36. payload
  37. });
  38. // -----------------------------------------------------------------------------------------------------------------
  39. export const setSheduleDoctor = payload => ({
  40. type: types.CHANGE_SHEDULE_DOCTOR,
  41. payload
  42. });
  43. // -----------------------------------------------------------------------------------------------------------------
  44. // const getAllRequest = payload => ({
  45. // type: types.GET_ALL_REQUEST,
  46. // payload
  47. // });
  48. //
  49. // const getAllRequestSuccess = payload => ({
  50. // type: types.GET_ALL_REQUEST_SUCCESS,
  51. // payload
  52. // });
  53. //
  54. // const getAllRequestFail = payload => ({
  55. // type: types.GET_ALL_REQUEST_FAIL,
  56. // payload
  57. // });
  58. //
  59. // export const getAll = () => dispatch => {
  60. // dispatch(getAllRequest());
  61. // return fetch(`${URL}.json`)
  62. // .then(res => res.json())
  63. // .then(res => dispatch(getAllRequestSuccess(res)))
  64. // .catch(err => dispatch(getAllRequestFail(err)));
  65. // };
  66. // -----------------------------------------------------------------------------------------------------------------
  67. // -----------------------------------------------------------------------------------------------------------------
  68. const getDoctorsRequest = payload => ({
  69. type: types.GET_DOCTORS_REQUEST,
  70. payload
  71. });
  72. const getDoctorsRequestSuccess = payload => ({
  73. type: types.GET_DOCTORS_REQUEST_SUCCESS,
  74. payload
  75. });
  76. const getDoctorsRequestFail = payload => ({
  77. type: types.GET_DOCTORS_REQUEST_FAIL,
  78. payload
  79. });
  80. export const getDoctors = () => dispatch => {
  81. dispatch(getDoctorsRequest());
  82. return fetch(`${URL}doctors`,{
  83. credentials:"include"
  84. })
  85. .then(res => res.json())
  86. .then(res => dispatch(getDoctorsRequestSuccess(res)))
  87. .catch(err => dispatch(getDoctorsRequestFail(err)));
  88. };
  89. // -----------------------------------------------------------------------------------------------------------------
  90. const getServicesRequest = payload => ({
  91. type: types.GET_SERVICES_REQUEST,
  92. payload
  93. });
  94. const getServicesRequestSuccess = payload => ({
  95. type: types.GET_SERVICES_REQUEST_SUCCESS,
  96. payload
  97. });
  98. const getServicesRequestFail = payload => ({
  99. type: types.GET_SERVICES_REQUEST_FAIL,
  100. payload
  101. });
  102. export const getServices = () => dispatch => {
  103. dispatch(getServicesRequest());
  104. return fetch(`${URL}services`,{
  105. credentials:"include"
  106. })
  107. .then(res => res.json())
  108. .then(res => dispatch(getServicesRequestSuccess(res)))
  109. .catch(err => dispatch(getServicesRequestFail(err)));
  110. };
  111. // -----------------------------------------------------------------------------------------------------------------
  112. // -----------------------------------------------------------------------------------------------------------------
  113. const postDoctorsRequest = payload => ({
  114. type: types.POST_DOCTORS_REQUEST,
  115. payload
  116. });
  117. const postDoctorsRequestSuccess = payload => ({
  118. type: types.POST_DOCTORS_REQUEST_SUCCESS,
  119. payload
  120. });
  121. const postDoctorsRequestFail = payload => ({
  122. type: types.POST_DOCTORS_REQUEST_FAIL,
  123. payload
  124. });
  125. export const postDoctors = (payload) => dispatch => {
  126. dispatch(postDoctorsRequest());
  127. return fetch(`${URL}doctors`, {
  128. method: "POST",
  129. credentials: "include",
  130. headers: {
  131. "Content-Type": "application/json"
  132. },
  133. body: JSON.stringify(payload)
  134. })
  135. .then(res => res.json())
  136. .then(res => dispatch(postDoctorsRequestSuccess(res)))
  137. .catch(err => dispatch(postDoctorsRequestFail(err)));
  138. };
  139. // -----------------------------------------------------------------------------------------------------------------
  140. const postServicesRequest = payload => ({
  141. type: types.POST_SERVICES_REQUEST,
  142. payload
  143. });
  144. const postServicesRequestSuccess = payload => ({
  145. type: types.POST_SERVICES_REQUEST_SUCCESS,
  146. payload
  147. });
  148. const postServicesRequestFail = payload => ({
  149. type: types.POST_SERVICES_REQUEST_FAIL,
  150. payload
  151. });
  152. export const postServices = (payload) => dispatch => {
  153. dispatch(postServicesRequest());
  154. return fetch(`${URL}services`, {
  155. method: "POST",
  156. credentials: "include",
  157. headers: {
  158. "Content-Type": "application/json"
  159. },
  160. body: JSON.stringify(payload)
  161. })
  162. .then(res => res.json())
  163. .then(res => dispatch(postServicesRequestSuccess(res)))
  164. .catch(err => dispatch(postServicesRequestFail(err)))
  165. };
  166. // -----------------------------------------------------------------------------------------------------------------
  167. const postSheduleRequest = payload => ({
  168. type: types.POST_SHEDULE_REQUEST,
  169. payload
  170. });
  171. const postSheduleSuccess = payload => ({
  172. type: types.POST_SHEDULE_REQUEST_SUCCESS,
  173. payload
  174. });
  175. const postSheduleFail = payload => ({
  176. type: types.POST_SHEDULE_REQUEST_FAIL,
  177. payload
  178. });
  179. export const postShedule = (payload) => dispatch => {
  180. dispatch(postSheduleRequest());
  181. return fetch(`${URL}shedule`, {
  182. method: "POST",
  183. credentials:"include",
  184. headers: {
  185. 'Content-Type': 'application/json'
  186. },
  187. body: JSON.stringify(payload)
  188. })
  189. .then(res => res.json())
  190. .then(res => dispatch(postSheduleSuccess(res)))
  191. .catch(err => dispatch(postSheduleFail(err)));
  192. };
  193. // -----------------------------------------------------------------------------------------------------------------
  194. const postOrdersRequest = payload => ({
  195. type: types.POST_ORDERS_REQUEST,
  196. payload
  197. });
  198. const postOrdersSuccess = payload => ({
  199. type: types.POST_ORDERS_REQUEST_SUCCESS,
  200. payload
  201. });
  202. const postOrdersFail = payload => ({
  203. type: types.POST_ORDERS_REQUEST_FAIL,
  204. payload
  205. });
  206. export const postOrders = (payload) => dispatch => {
  207. dispatch(postOrdersRequest());
  208. return fetch(`${URL}orders`, {
  209. method: "POST",
  210. credentials:"include",
  211. headers: {
  212. 'Content-Type': 'application/json'
  213. },
  214. body: JSON.stringify(payload)
  215. })
  216. .then(res => res.json())
  217. .then(res => dispatch(postOrdersSuccess(res)))
  218. .catch(err => dispatch(postOrdersFail(err)));
  219. };
  220. // -----------------------------------------------------------------------------------------------------------------
  221. const putDoctorsRequest = payload => ({
  222. type: types.PUT_DOCTORS_REQUEST,
  223. payload
  224. });
  225. const putDoctorsRequestSuccess = payload => ({
  226. type: types.PUT_DOCTORS_REQUEST_SUCCESS,
  227. payload
  228. });
  229. const putDoctorsRequestFail = payload => ({
  230. type: types.PUT_DOCTORS_REQUEST_FAIL,
  231. payload
  232. });
  233. export const putDoctors = (payload) => dispatch => {
  234. dispatch(putDoctorsRequest());
  235. return fetch(`${URL}doctors/${payload.id}`, {
  236. method: "PUT",
  237. credentials: "include",
  238. headers: {
  239. "Content-Type": "application/json"
  240. },
  241. body: JSON.stringify(payload.data)
  242. })
  243. .then(res => res.json())
  244. .then(res => dispatch(putDoctorsRequestSuccess(res)))
  245. .catch(err => dispatch(putDoctorsRequestFail(err)));
  246. };
  247. // -----------------------------------------------------------------------------------------------------------------