searchStaffByIdAction.js 909 B

123456789101112131415161718192021222324252627282930313233
  1. import * as types from '../constants/actionTypes';
  2. const axios = require('axios')
  3. const SeacrhStaffRequestById = payload => ({
  4. type: types.SEARCH_STAFF_REQUEST_BY_ID,
  5. payload
  6. });
  7. const SeacrhStaffRequestSuccessById = payload => ({
  8. type: types.SEARCH_STAFF_REQUEST_SUCCESS_BY_ID,
  9. payload
  10. });
  11. const SeacrhStaffRequestFailById = payload => ({
  12. type: types.SEARCH_STAFF_REQUEST_FAIL_BY_ID,
  13. payload
  14. });
  15. export const getSeacrhStaffsDataById = (payload)=>{
  16. return dispatch => {
  17. dispatch(SeacrhStaffRequestById());
  18. return axios.get(`http://127.0.0.1:2000/api/staffs?id=${payload}`)
  19. .then(res => {
  20. setTimeout(()=>{dispatch(SeacrhStaffRequestSuccessById(res))},Math.random()*1000);
  21. })
  22. .catch(err=>{
  23. dispatch(SeacrhStaffRequestFailById(err));
  24. })
  25. };
  26. };