Functionality to add prices as a client, and view them as a provider
This commit is contained in:
@@ -59,6 +59,16 @@ import {
|
||||
} from "./employee.sagas";
|
||||
import { UPDATE_EMPLOYER_REQUEST } from "../constants/employer.constants";
|
||||
import { updateEmployerFlow } from "./employer.sagas";
|
||||
import {
|
||||
CREATE_PRICE_REQUEST,
|
||||
UPDATE_PRICE_REQUEST,
|
||||
DELETE_PRICE_REQUEST
|
||||
} from "../constants/price.constants";
|
||||
import {
|
||||
createPriceFlow,
|
||||
updatePriceFlow,
|
||||
deletePriceFlow
|
||||
} from "./price.sagas";
|
||||
|
||||
export default function* rootSaga() {
|
||||
yield takeLatest(SEND_REGISTER_REQUEST, registerUserFlow);
|
||||
@@ -83,4 +93,7 @@ export default function* rootSaga() {
|
||||
yield takeLatest(READ_EMPLOYEE_REQUEST, readEmployeeFlow);
|
||||
yield takeLatest(DELETE_EMPLOYEE_REQUEST, deleteEmployeeFlow);
|
||||
yield takeLatest(UPDATE_EMPLOYER_REQUEST, updateEmployerFlow);
|
||||
yield takeLatest(CREATE_PRICE_REQUEST, createPriceFlow);
|
||||
yield takeLatest(UPDATE_PRICE_REQUEST, updatePriceFlow);
|
||||
yield takeLatest(DELETE_PRICE_REQUEST, deletePriceFlow);
|
||||
}
|
||||
|
||||
85
src/sagas/price.sagas.js
Normal file
85
src/sagas/price.sagas.js
Normal file
@@ -0,0 +1,85 @@
|
||||
import { effects } from "redux-saga";
|
||||
import {
|
||||
isSendingPriceRequest,
|
||||
setPriceRequestError,
|
||||
clearPriceRequestError,
|
||||
setPriceRequestSuccess,
|
||||
clearPriceRequestSuccess,
|
||||
setGetEmployeeUUID,
|
||||
setGetWorktypeUUID,
|
||||
setFormPriceAmount
|
||||
} from "../actions/price/reducer.actions";
|
||||
import { getSelfUserRequest } from "../actions/user/saga.actions";
|
||||
import { createPrice, updatePrice, deletePrice } from "../api/price.api";
|
||||
|
||||
function* createPriceCall(postBody) {
|
||||
yield effects.put(isSendingPriceRequest(true));
|
||||
const { get_employee_uuid, get_work_type_uuid, amount } = postBody;
|
||||
try {
|
||||
return yield effects.call(
|
||||
createPrice,
|
||||
get_employee_uuid,
|
||||
get_work_type_uuid,
|
||||
amount
|
||||
);
|
||||
} catch (exception) {
|
||||
yield effects.put(setPriceRequestError(exception));
|
||||
return false;
|
||||
} finally {
|
||||
yield effects.put(isSendingPriceRequest(false));
|
||||
}
|
||||
}
|
||||
|
||||
function* updatePriceCall(payload) {
|
||||
yield effects.put(isSendingPriceRequest(true));
|
||||
const { uuid, amount } = payload;
|
||||
try {
|
||||
return yield effects.call(updatePrice, uuid, amount);
|
||||
} catch (exception) {
|
||||
yield effects.put(setPriceRequestError(exception));
|
||||
return false;
|
||||
} finally {
|
||||
yield effects.put(isSendingPriceRequest(false));
|
||||
}
|
||||
}
|
||||
|
||||
function* deletePriceCall(uuid) {
|
||||
yield effects.put(isSendingPriceRequest(true));
|
||||
try {
|
||||
return yield effects.call(deletePrice, uuid);
|
||||
} catch (exception) {
|
||||
yield effects.put(setPriceRequestError(exception));
|
||||
return false;
|
||||
} finally {
|
||||
yield effects.put(isSendingPriceRequest(false));
|
||||
}
|
||||
}
|
||||
|
||||
export function* createPriceFlow(request) {
|
||||
yield effects.put(clearPriceRequestSuccess());
|
||||
yield effects.put(clearPriceRequestError());
|
||||
const wasSuccessful = yield effects.call(createPriceCall, request.data);
|
||||
if (wasSuccessful) {
|
||||
yield effects.put(getSelfUserRequest());
|
||||
yield effects.put(setPriceRequestSuccess(wasSuccessful));
|
||||
yield effects.put(setGetEmployeeUUID(""));
|
||||
yield effects.put(setGetWorktypeUUID(""));
|
||||
yield effects.put(setFormPriceAmount(""));
|
||||
yield effects.put(clearPriceRequestError());
|
||||
}
|
||||
}
|
||||
|
||||
export function* updatePriceFlow(request) {
|
||||
yield effects.put(clearPriceRequestSuccess());
|
||||
yield effects.put(clearPriceRequestError());
|
||||
const wasSuccessful = yield effects.call(updatePriceCall, request.data);
|
||||
if (wasSuccessful) {
|
||||
yield effects.put(getSelfUserRequest());
|
||||
yield effects.put(setPriceRequestSuccess(wasSuccessful));
|
||||
}
|
||||
}
|
||||
|
||||
export function* deletePriceFlow(request) {
|
||||
yield effects.call(deletePriceCall, request.data);
|
||||
yield effects.put(getSelfUserRequest());
|
||||
}
|
||||
Reference in New Issue
Block a user