import { effects } from "redux-saga"; import { isSendingEmployerRequest, setEmployerRequestError, setEmployerRequestSuccess, clearEmployerRequestError, clearEmployerRequestSuccess } from "../actions/employer/reducer.actions"; import { getSelfUserRequest } from "../actions/user/saga.actions"; import { updateEmployer } from "../api/employer.api"; function* updateEmployerCall(payload) { yield effects.put(isSendingEmployerRequest(true)); const { uuid, approved } = payload; try { return yield effects.call(updateEmployer, uuid, approved); } catch (exception) { yield effects.put(setEmployerRequestError(exception)); return false; } finally { yield effects.put(isSendingEmployerRequest(false)); } } export function* updateEmployerFlow(request) { yield effects.put(clearEmployerRequestSuccess()); yield effects.put(clearEmployerRequestError()); const wasSuccessful = yield effects.call(updateEmployerCall, request.data); if (wasSuccessful) { yield effects.put(getSelfUserRequest()); yield effects.put(setEmployerRequestSuccess(wasSuccessful)); yield effects.put(clearEmployerRequestError()); } }