Functionality to add prices as a client, and view them as a provider
This commit is contained in:
@@ -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