Create/Update worktypes
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
||||
logoutUserFlow,
|
||||
changePasswordFlow,
|
||||
forgotPasswordFlow,
|
||||
resetPasswordFlow,
|
||||
resetPasswordFlow
|
||||
} from "./auth.sagas";
|
||||
import {
|
||||
GET_SELF_USER_REQUEST,
|
||||
@@ -35,6 +35,16 @@ import {
|
||||
createProviderFlow,
|
||||
updateProviderFlow
|
||||
} from "./user.sagas";
|
||||
import {
|
||||
CREATE_WORKTYPE_REQUEST,
|
||||
READ_WORKTYPE_REQUEST,
|
||||
UPDATE_WORKTYPE_REQUEST
|
||||
} from "../constants/worktype.constants";
|
||||
import {
|
||||
createWorktypeFlow,
|
||||
readWorktypeFlow,
|
||||
updateWorktypeFlow
|
||||
} from "./worktype.sagas";
|
||||
|
||||
export default function* rootSaga() {
|
||||
yield takeLatest(SEND_REGISTER_REQUEST, registerUserFlow);
|
||||
@@ -51,4 +61,7 @@ export default function* rootSaga() {
|
||||
yield takeLatest(UPDATE_CLIENT_REQUEST, updateClientFlow);
|
||||
yield takeLatest(CREATE_PROVIDER_REQUEST, createProviderFlow);
|
||||
yield takeLatest(UPDATE_PROVIDER_REQUEST, updateProviderFlow);
|
||||
yield takeLatest(CREATE_WORKTYPE_REQUEST, createWorktypeFlow);
|
||||
yield takeLatest(READ_WORKTYPE_REQUEST, readWorktypeFlow);
|
||||
yield takeLatest(UPDATE_WORKTYPE_REQUEST, updateWorktypeFlow);
|
||||
}
|
||||
|
||||
88
src/sagas/worktype.sagas.js
Normal file
88
src/sagas/worktype.sagas.js
Normal file
@@ -0,0 +1,88 @@
|
||||
import { effects } from "redux-saga";
|
||||
import {
|
||||
isSendingWorktypeRequest,
|
||||
setWorktypeRequestError,
|
||||
setWorktypeRequestSuccess,
|
||||
clearWorktypeRequestError,
|
||||
clearWorktypeRequestSuccess,
|
||||
setWorktypeUUID,
|
||||
setFormWorktypeColor,
|
||||
setFormWorktypeLabel
|
||||
} from "../actions/worktype/reducer.actions";
|
||||
import { getSelfUserRequest } from "../actions/user/saga.actions";
|
||||
import {
|
||||
createWorktype,
|
||||
getWorktype,
|
||||
updateWorktype,
|
||||
deleteWorktype
|
||||
} from "../api/worktype.api";
|
||||
|
||||
function* createWorktypeCall(postBody) {
|
||||
yield effects.put(isSendingWorktypeRequest(true));
|
||||
const { color, label } = postBody;
|
||||
try {
|
||||
return yield effects.call(createWorktype, color, label);
|
||||
} catch (exception) {
|
||||
yield effects.put(setWorktypeRequestError(exception));
|
||||
return false;
|
||||
} finally {
|
||||
yield effects.put(isSendingWorktypeRequest(false));
|
||||
}
|
||||
}
|
||||
|
||||
function* readWorktypeCall(uuid) {
|
||||
yield effects.put(isSendingWorktypeRequest(true));
|
||||
try {
|
||||
return yield effects.call(getWorktype, uuid);
|
||||
} catch (exception) {
|
||||
yield effects.put(setWorktypeRequestError(exception));
|
||||
return false;
|
||||
} finally {
|
||||
yield effects.put(isSendingWorktypeRequest(false));
|
||||
}
|
||||
}
|
||||
|
||||
function* updateWorktypeCall(payload) {
|
||||
yield effects.put(isSendingWorktypeRequest(true));
|
||||
const { uuid, color } = payload;
|
||||
try {
|
||||
return yield effects.call(updateWorktype, uuid, color);
|
||||
} catch (exception) {
|
||||
yield effects.put(setWorktypeRequestError(exception));
|
||||
return false;
|
||||
} finally {
|
||||
yield effects.put(isSendingWorktypeRequest(false));
|
||||
}
|
||||
}
|
||||
|
||||
export function* createWorktypeFlow(request) {
|
||||
yield effects.put(clearWorktypeRequestSuccess());
|
||||
yield effects.put(clearWorktypeRequestError());
|
||||
const wasSuccessful = yield effects.call(createWorktypeCall, request.data);
|
||||
if (wasSuccessful) {
|
||||
yield effects.put(getSelfUserRequest());
|
||||
yield effects.put(setWorktypeRequestSuccess(wasSuccessful));
|
||||
yield effects.put(setFormWorktypeColor(""));
|
||||
yield effects.put(setFormWorktypeLabel(""));
|
||||
yield effects.put(clearWorktypeRequestError());
|
||||
}
|
||||
}
|
||||
|
||||
export function* readWorktypeFlow(request) {
|
||||
const wasSuccessful = yield effects.call(readWorktypeCall, request.data);
|
||||
if (wasSuccessful) {
|
||||
yield effects.put(setWorktypeUUID(wasSuccessful.uuid));
|
||||
yield effects.put(setFormWorktypeColor(wasSuccessful.color));
|
||||
yield effects.put(setFormWorktypeLabel(wasSuccessful.label));
|
||||
}
|
||||
}
|
||||
|
||||
export function* updateWorktypeFlow(request) {
|
||||
yield effects.put(clearWorktypeRequestSuccess());
|
||||
yield effects.put(clearWorktypeRequestError());
|
||||
const wasSuccessful = yield effects.call(updateWorktypeCall, request.data);
|
||||
if (wasSuccessful) {
|
||||
yield effects.put(getSelfUserRequest());
|
||||
yield effects.put(setWorktypeRequestSuccess(wasSuccessful));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user