functionality for client users to add providers
This commit is contained in:
100
src/sagas/employee.sagas.js
Normal file
100
src/sagas/employee.sagas.js
Normal file
@@ -0,0 +1,100 @@
|
||||
import { effects } from "redux-saga";
|
||||
import {
|
||||
isSendingEmployeeRequest,
|
||||
setEmployeeRequestError,
|
||||
setEmployeeRequestSuccess,
|
||||
clearEmployeeRequestError,
|
||||
clearEmployeeRequestSuccess,
|
||||
setEmployeeUUID,
|
||||
setFormEmployeeEmail,
|
||||
setFormEmployeeNote
|
||||
} from "../actions/employee/reducer.actions";
|
||||
import { getSelfUserRequest } from "../actions/user/saga.actions";
|
||||
import { addEmployee, getEmployee, deleteEmployee, updateEmployee } from "../api/employee.api";
|
||||
|
||||
function* addEmployeeCall(postBody) {
|
||||
yield effects.put(isSendingEmployeeRequest(true));
|
||||
const { provider_email, note } = postBody;
|
||||
try {
|
||||
return yield effects.call(addEmployee, provider_email, note);
|
||||
} catch (exception) {
|
||||
yield effects.put(setEmployeeRequestError(exception));
|
||||
return false;
|
||||
} finally {
|
||||
yield effects.put(isSendingEmployeeRequest(false));
|
||||
}
|
||||
}
|
||||
|
||||
function* readEmployeeCall(uuid) {
|
||||
yield effects.put(isSendingEmployeeRequest(true));
|
||||
try {
|
||||
return yield effects.call(getEmployee, uuid);
|
||||
} catch (exception) {
|
||||
yield effects.put(setEmployeeRequestError(exception));
|
||||
return false;
|
||||
} finally {
|
||||
yield effects.put(isSendingEmployeeRequest(false));
|
||||
}
|
||||
}
|
||||
|
||||
function* updateEmployeeCall(payload) {
|
||||
yield effects.put(isSendingEmployeeRequest(true));
|
||||
const { uuid, provider_email, note } = payload;
|
||||
try {
|
||||
return yield effects.call(updateEmployee, uuid, provider_email, note);
|
||||
} catch (exception) {
|
||||
yield effects.put(setEmployeeRequestError(exception));
|
||||
return false;
|
||||
} finally {
|
||||
yield effects.put(isSendingEmployeeRequest(false))
|
||||
}
|
||||
}
|
||||
|
||||
function* deleteEmployeeCall(uuid) {
|
||||
yield effects.put(isSendingEmployeeRequest(true));
|
||||
try {
|
||||
return yield effects.call(deleteEmployee, uuid);
|
||||
} catch (exception) {
|
||||
yield effects.put(setEmployeeRequestError(exception));
|
||||
return false;
|
||||
} finally {
|
||||
yield effects.put(isSendingEmployeeRequest(false));
|
||||
}
|
||||
}
|
||||
|
||||
export function* addEmployeeFlow(request) {
|
||||
yield effects.put(clearEmployeeRequestSuccess());
|
||||
yield effects.put(clearEmployeeRequestError());
|
||||
const wasSuccessful = yield effects.call(addEmployeeCall, request.data);
|
||||
if (wasSuccessful) {
|
||||
yield effects.put(getSelfUserRequest());
|
||||
yield effects.put(setEmployeeRequestSuccess(wasSuccessful));
|
||||
yield effects.put(setFormEmployeeEmail(""));
|
||||
yield effects.put(setFormEmployeeNote(""));
|
||||
yield effects.put(clearEmployeeRequestError());
|
||||
}
|
||||
}
|
||||
|
||||
export function* readEmployeeFlow(request) {
|
||||
const wasSuccessful = yield effects.call(readEmployeeCall, request.data);
|
||||
if (wasSuccessful) {
|
||||
yield effects.put(setEmployeeUUID(wasSuccessful.uuid))
|
||||
yield effects.put(setFormEmployeeEmail(wasSuccessful.provider_email));
|
||||
yield effects.put(setFormEmployeeNote(wasSuccessful.note))
|
||||
}
|
||||
}
|
||||
|
||||
export function* updateEmployeeFlow(request) {
|
||||
yield effects.put(clearEmployeeRequestSuccess());
|
||||
yield effects.put(clearEmployeeRequestError());
|
||||
const wasSuccessful = yield effects.call(updateEmployeeCall, request.data);
|
||||
if (wasSuccessful) {
|
||||
yield effects.put(getSelfUserRequest());
|
||||
yield effects.put(setEmployeeRequestSuccess(wasSuccessful));
|
||||
}
|
||||
}
|
||||
|
||||
export function* deleteEmployeeFlow(request) {
|
||||
yield effects.call(deleteEmployeeCall, request.data);
|
||||
yield effects.put(getSelfUserRequest());
|
||||
}
|
||||
@@ -47,6 +47,16 @@ import {
|
||||
updateWorktypeFlow,
|
||||
deleteWorktypeFlow
|
||||
} from "./worktype.sagas";
|
||||
import {
|
||||
CREATE_EMPLOYEE_REQUEST,
|
||||
READ_EMPLOYEE_REQUEST,
|
||||
DELETE_EMPLOYEE_REQUEST
|
||||
} from "../constants/employee.constants";
|
||||
import {
|
||||
addEmployeeFlow,
|
||||
readEmployeeFlow,
|
||||
deleteEmployeeFlow
|
||||
} from "./employee.sagas";
|
||||
|
||||
export default function* rootSaga() {
|
||||
yield takeLatest(SEND_REGISTER_REQUEST, registerUserFlow);
|
||||
@@ -67,4 +77,7 @@ export default function* rootSaga() {
|
||||
yield takeLatest(READ_WORKTYPE_REQUEST, readWorktypeFlow);
|
||||
yield takeLatest(UPDATE_WORKTYPE_REQUEST, updateWorktypeFlow);
|
||||
yield takeLatest(DELETE_WORKTYPE_REQUEST, deleteWorktypeFlow);
|
||||
yield takeLatest(CREATE_EMPLOYEE_REQUEST, addEmployeeFlow);
|
||||
yield takeLatest(READ_EMPLOYEE_REQUEST, readEmployeeFlow);
|
||||
yield takeLatest(DELETE_EMPLOYEE_REQUEST, deleteEmployeeFlow);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user