31 lines
899 B
JavaScript
31 lines
899 B
JavaScript
|
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));
|
||
|
}
|
||
|
}
|