caremyway-client/src/sagas/pShift.sagas.js

31 lines
899 B
JavaScript
Raw Normal View History

2018-04-23 05:04:09 +00:00
import { effects } from "redux-saga";
import {
isSendingPShiftRequest,
setPShiftRequestError,
setPShiftRequestSuccess,
clearPShiftRequestError,
clearPShiftRequestSuccess
} from "../actions/pShift/reducer.actions";
import { getPShifts } from "../api/pShift.api";
function* getPShiftsCall(params) {
yield effects.put(isSendingPShiftRequest(true));
try {
return yield effects.call(getPShifts, params);
} catch (exception) {
yield effects.put(setPShiftRequestError(exception));
return false;
} finally {
yield effects.put(isSendingPShiftRequest(false));
}
}
export function* getPShiftsFlow(request) {
yield effects.put(clearPShiftRequestSuccess());
yield effects.put(clearPShiftRequestError());
const wasSuccessful = yield effects.call(getPShiftsCall, request.data);
if (wasSuccessful) {
yield effects.put(setPShiftRequestSuccess(wasSuccessful));
}
}