You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
4.3 KiB
149 lines
4.3 KiB
import { effects } from "redux-saga"; |
|
import { |
|
isSendingCShiftRequest, |
|
setCShiftRequestError, |
|
setCShiftRequestErrors, |
|
setCShiftRequestSuccess, |
|
clearCShiftRequestError, |
|
clearCShiftRequestSuccess, |
|
setFormEmployeeUUID, |
|
setFormPriceUUID, |
|
setFormShiftDates, |
|
setFormShiftDuration, |
|
setFormShiftNote, |
|
setFormShiftStartTime, |
|
setCShiftUUID |
|
} from "../actions/cShift/reducer.actions"; |
|
import { |
|
createCShifts, |
|
getCShifts, |
|
getCShift, |
|
editCShift, |
|
deleteCShift |
|
} from "../api/cShift.api"; |
|
import { getCShiftsRequest } from "../actions/cShift/saga.actions"; |
|
|
|
function* createCShiftsCall(postBodies) { |
|
yield effects.put(isSendingCShiftRequest(true)); |
|
try { |
|
if (postBodies.length > 0) { |
|
return yield effects.call(createCShifts, postBodies); |
|
} else { |
|
yield effects.put( |
|
setCShiftRequestError({ |
|
response: { data: { dates: ["No dates selected."] } } |
|
}) |
|
); |
|
return false; |
|
} |
|
} catch (exception) { |
|
yield effects.put(setCShiftRequestError(exception)); |
|
return false; |
|
} finally { |
|
yield effects.put(isSendingCShiftRequest(false)); |
|
} |
|
} |
|
|
|
function* getCShiftsCall(params) { |
|
yield effects.put(isSendingCShiftRequest(true)); |
|
try { |
|
return yield effects.call(getCShifts, params); |
|
} catch (exception) { |
|
yield effects.put(setCShiftRequestError(exception)); |
|
return false; |
|
} finally { |
|
yield effects.put(isSendingCShiftRequest(false)); |
|
} |
|
} |
|
|
|
function* getCShiftCall({ uuid, params }) { |
|
yield effects.put(isSendingCShiftRequest(true)); |
|
try { |
|
return yield effects.call(getCShift, uuid, params); |
|
} catch (exception) { |
|
yield effects.put(setCShiftRequestError(exception)); |
|
return false; |
|
} finally { |
|
yield effects.put(isSendingCShiftRequest(false)); |
|
} |
|
} |
|
|
|
function* editCShiftCall(payload) { |
|
yield effects.put(isSendingCShiftRequest(true)); |
|
try { |
|
const edit = yield effects.call(editCShift, payload.uuid, payload); |
|
yield effects.put(setCShiftUUID(true)); |
|
return edit; |
|
} catch (exception) { |
|
yield effects.put(setCShiftRequestError(exception)); |
|
return false; |
|
} finally { |
|
yield effects.put(isSendingCShiftRequest(false)); |
|
} |
|
} |
|
|
|
function* deleteCShiftCall(uuid) { |
|
yield effects.put(isSendingCShiftRequest(true)); |
|
try { |
|
return yield effects.call(deleteCShift, uuid); |
|
} catch (exception) { |
|
yield effects.put(setCShiftRequestError(exception)); |
|
return false; |
|
} finally { |
|
yield effects.put(isSendingCShiftRequest(false)); |
|
} |
|
} |
|
|
|
export function* createCShiftsFlow(request) { |
|
yield effects.put(clearCShiftRequestSuccess()); |
|
yield effects.put(clearCShiftRequestError()); |
|
const arrResponses = yield effects.call(createCShiftsCall, request.data); |
|
if (arrResponses) { |
|
const errorResps = arrResponses.filter(resp => !!resp.error); |
|
if (errorResps.length > 0) { |
|
yield effects.put(setCShiftRequestErrors(errorResps)); |
|
} |
|
const succResps = arrResponses.filter(resp => !resp.error); |
|
if (succResps.length > 0) { |
|
yield effects.put(setCShiftRequestSuccess(succResps)); |
|
yield effects.put(setFormEmployeeUUID("")); |
|
yield effects.put(setFormPriceUUID("")); |
|
yield effects.put(setFormShiftStartTime(null)); |
|
yield effects.put(setFormShiftDuration("")); |
|
yield effects.put(setFormShiftNote("")); |
|
yield effects.put(setFormShiftDates({})); |
|
} |
|
} |
|
} |
|
|
|
export function* getCShiftsFlow(request) { |
|
yield effects.put(clearCShiftRequestSuccess()); |
|
yield effects.put(clearCShiftRequestError()); |
|
const isSuccessful = yield effects.call(getCShiftsCall, request.data); |
|
if (isSuccessful) { |
|
yield effects.put(setCShiftRequestSuccess(isSuccessful)); |
|
} |
|
} |
|
|
|
export function* getCShiftFlow(request) { |
|
yield effects.put(clearCShiftRequestSuccess()); |
|
yield effects.put(clearCShiftRequestError()); |
|
const wasSuccessful = yield effects.call(getCShiftCall, request.data); |
|
if (wasSuccessful) { |
|
yield effects.put(setCShiftRequestSuccess(wasSuccessful)); |
|
} |
|
} |
|
|
|
export function* editCShiftFlow(request) { |
|
yield effects.put(clearCShiftRequestError()); |
|
const wasSuccessful = yield effects.call(editCShiftCall, request.data); |
|
if (wasSuccessful) { |
|
yield effects.put(setCShiftRequestSuccess(wasSuccessful)); |
|
} |
|
} |
|
|
|
export function* deleteCShiftFlow(request) { |
|
yield effects.put(clearCShiftRequestError()); |
|
yield effects.call(deleteCShiftCall, request.data); |
|
yield effects.put(getCShiftsRequest({ page: 1 })); |
|
}
|
|
|