getUser.js 765 B

12345678910111213141516171819202122232425262728
  1. import { put, call } from 'redux-saga/effects';
  2. import axios from 'axios';
  3. import { GET_USERS } from './../../../constants/admin';
  4. import { getUserSuccess, getUserFailure } from './../../../actions/admin/user/getUser';
  5. import storageKey from '../../../utils/storageKey';
  6. const getItem = localStorage.getItem(storageKey);
  7. export default function* (payload) {
  8. try {
  9. const config = {
  10. headers: {
  11. "Content-Type": "application/json",
  12. "Authorization": `Bearer ${getItem}`
  13. }
  14. }
  15. const user = yield call(() =>
  16. axios.get(GET_USERS , config)
  17. )
  18. yield put(getUserSuccess(user));
  19. }
  20. catch ({ message }) {
  21. yield put(getUserFailure(message));
  22. }
  23. }