working edit cshift functionality

This commit is contained in:
Alexander Wong
2018-04-22 21:07:50 -06:00
parent 0950f264e8
commit 4f548d529f
13 changed files with 543 additions and 160 deletions

View File

@@ -11,9 +11,15 @@ import {
setFormShiftDates,
setFormShiftDuration,
setFormShiftNote,
setFormShiftStartTime
setFormShiftStartTime,
setCShiftUUID
} from "../actions/cShift/reducer.actions";
import { createCShifts, getCShifts } from "../api/cShift.api";
import {
createCShifts,
getCShifts,
getCShift,
editCShift
} from "../api/cShift.api";
function* createCShiftsCall(postBodies) {
yield effects.put(isSendingCShiftRequest(true));
@@ -48,6 +54,32 @@ function* getCShiftsCall(params) {
}
}
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));
}
}
export function* createCShiftsFlow(request) {
yield effects.put(clearCShiftRequestSuccess());
yield effects.put(clearCShiftRequestError());
@@ -78,3 +110,20 @@ export function* getCShiftsFlow(request) {
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));
}
}

View File

@@ -71,9 +71,16 @@ import {
} from "./price.sagas";
import {
CREATE_MULTIPLE_CSHIFT_REQUEST,
GET_CSHIFTS_REQUEST
GET_CSHIFTS_REQUEST,
GET_CSHIFT_REQUEST,
EDIT_CSHIFT_REQUEST
} from "../constants/cShift.constants";
import { createCShiftsFlow, getCShiftsFlow } from "./cShift.sagas";
import {
createCShiftsFlow,
getCShiftsFlow,
getCShiftFlow,
editCShiftFlow
} from "./cShift.sagas";
export default function* rootSaga() {
yield takeLatest(SEND_REGISTER_REQUEST, registerUserFlow);
@@ -103,4 +110,6 @@ export default function* rootSaga() {
yield takeLatest(DELETE_PRICE_REQUEST, deletePriceFlow);
yield takeLatest(CREATE_MULTIPLE_CSHIFT_REQUEST, createCShiftsFlow);
yield takeLatest(GET_CSHIFTS_REQUEST, getCShiftsFlow);
yield takeLatest(GET_CSHIFT_REQUEST, getCShiftFlow);
yield takeLatest(EDIT_CSHIFT_REQUEST, editCShiftFlow);
}