Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. export const setLoader = (loader) => dispatch => {
  2. dispatch({ type: SET_LOADER, payload: loader });
  3. };
  4.  
  5. export const fetchCategory = (setLoader) => async dispatch => {
  6. setLoader(true);
  7. try {
  8. const instance = axios.create();
  9. instance.defaults.headers.common['Authorization'] = AUTHORIZATION_TOKEN;
  10. const response = await instance.get(API_PATHS.SERVICE_CATEGORY_API);
  11.  
  12. dispatch({ type: FETCH_CATEGORY, payload: response.data });
  13.  
  14. } catch (e) {
  15. setLoader(false);
  16. }
  17.  
  18. };
  19.  
  20. export default (state = INITIAL_STATE, action) => {
  21.  
  22. switch (action.type) {
  23. case FETCH_CATEGORY:
  24. return { ...state, categoryList: action.payload };
  25. case SET_LOADER:
  26. return { ...state, isLoading: action.payload };
  27. default:
  28. return state;
  29. }
  30. };
  31.  
  32. const mapStateToProps = state => {
  33. return ({
  34. categoryList: state.locator.categoryList
  35. });
  36. }
  37.  
  38. export default connect(
  39. mapStateToProps,
  40. { fetchCategory, setLoader }
  41. )(ServiceLocator);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement