staffsAction.js 745 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import * as types from "../constants/actionTypes";
  2. const axios = require('axios');
  3. export const getInfoStaffData = payload => ({
  4. type: types.GET_STAFF_INFO_DATA,
  5. payload
  6. })
  7. const StaffRequest = payload => ({
  8. type: types.STAFF_REQUEST,
  9. payload
  10. });
  11. const StaffRequestSuccess = payload => ({
  12. type: types.STAFF_REQUEST_SUCCESS,
  13. payload
  14. });
  15. const StaffRequestFail = payload => ({
  16. type: types.STAFF_REQUEST_FAIL,
  17. payload
  18. });
  19. export const getStaffsData = () => {
  20. return dispatch => {
  21. dispatch(StaffRequest());
  22. return axios.get(`http://127.0.0.1:2000/api/staffs`)
  23. .then(res => {
  24. setTimeout(() => {
  25. dispatch(StaffRequestSuccess(res))
  26. }, 1000);
  27. })
  28. .catch(err => {
  29. dispatch(StaffRequestFail(err));
  30. })
  31. };
  32. };