SHARE
TWEET

Untitled

a guest Jun 19th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top