serviceRequest.js 501 Bytes
Newer Older
quynhquang400@gmail.com's avatar
quynhquang400@gmail.com committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import {finishLoading, startLoading} from './loaderSlice';

const serviceRequest = async serviceRequestProps => {
  const {options, dispatch, serviceMethod, payload} = serviceRequestProps;
  try {
    if (!options.skipLoader) {
      dispatch(startLoading());
    }
    const serviceRequestResponse = await serviceMethod(payload);
    return serviceRequestResponse;
  } catch {
  } finally {
    if (!options.skipLoader) {
      dispatch(finishLoading());
    }
  }
};

export default serviceRequest;