add getemployeebyid call N costcenter dropdown

This commit is contained in:
jfrye122
2023-05-09 12:27:06 -04:00
parent 9fc2d4c67c
commit e57a3605b8
8 changed files with 103 additions and 42 deletions

View File

@@ -19,13 +19,13 @@ export const employeeSignOut = () => ({
type: EmployeeActionTypes.EMPLOYEE_SIGN_OUT,
});
export const employeeGetRatesStart = (id) => ({
export const employeeGetRatesStart = (employeeId) => ({
type: EmployeeActionTypes.EMPLOYEE_GET_RATES_START,
payload: id,
payload: employeeId,
});
export const employeeGetRatesSuccess = (technician) => ({
export const employeeGetRatesSuccess = (employees_by_pk) => ({
type: EmployeeActionTypes.EMPLOYEE_GET_RATES_SUCCESS,
payload: technician,
payload: employees_by_pk,
});
export const employeeGetRatesFailure = (error) => ({
type: EmployeeActionTypes.EMPLOYEE_GET_RATES_FAILURE,

View File

@@ -46,8 +46,7 @@ const employeeReducer = (state = INITIAL_STATE, action) => {
case EmployeeActionTypes.EMPLOYEE_GET_RATES_SUCCESS:
return {
...state,
//currentEmployee: { authorized: true, technician:action.payload },
currentEmployee: { rates:action.payload },//TODO check if ...state needed
currentEmployee: { ...state.currentEmployee, technician:action.payload },
gettingRates: false,
error: null,
};

View File

@@ -13,6 +13,8 @@ import { logImEXEvent } from "../../firebase/firebase.analytics";
import { selectBodyshop } from "../user/user.selectors";
import axios from "axios";
import { client } from "../../graphql/client";
import { QUERY_EMPLOYEE_BY_ID } from "../../graphql/employees.queries";
import { selectCurrentEmployee } from "./employee.selectors";
export function* onSignInEmployeeStart() {
yield takeLatest(
@@ -43,34 +45,68 @@ export function* signInWithEmployeeId({ payload: { employeeId, pin } }) {
}
}
/*
//Waits for EMPLOYEE_SIGN_IN_SUCCESS when logging in to then call QUERY_EMPLOYEE_BY_ID with the id in payload to override technician with more data like rates and flat_rate
*/
export function* onEmployeeSignInSuccessSaga() {
yield takeLatest(
EmployeeActionTypes.EMPLOYEE_SIGN_IN_SUCCESS,
updateEmployeeWithEmployeeId
);
}
export function* updateEmployeeWithEmployeeId({ payload }) {
try {
const employeeId = payload.id;
// logImEXEvent("redux_update_employee_with_employee_id_attempt", employeeId);
const result = yield client.query({ query: QUERY_EMPLOYEE_BY_ID,
variables: {
id: employeeId,
}
});
const { employees_by_pk } = result.data;
if (employees_by_pk) {
yield put(employeeGetRatesSuccess(employees_by_pk));
} else {
yield put(employeeGetRatesFailure(result.error));
}
} catch (error) {
yield put(employeeGetRatesFailure(error));
console.log("Error while getting employee rates.", error);
//Sentry.Native.captureException(error);
}
}
export function* onEmployeeGetRatesStart() {
yield takeLatest(
EmployeeActionTypes.EMPLOYEE_GET_RATES_START,
getRatesWithEmployeeId
);
}
export function* getRatesWithEmployeeId({ payload }) {
export function* getRatesWithEmployeeId({ payload: employeeId }) {
try {
const response = yield client.query({ query: QUERY_EMPLOYEE_BY_ID,
logImEXEvent("redux_employee_get_rates_attempt", employeeId);
const result = yield client.query({ query: QUERY_EMPLOYEE_BY_ID,
variables: {
id: payload.id,
id: employeeId,
}
});
logImEXEvent("redux_employee_get_rates_attempt", payload);
const { valid, technician, error } = response.data;
const { employees_by_pk } = result.data;
if (valid) {
yield put(employeeGetRatesSuccess(technician));
if (employees_by_pk) {
yield put(employeeGetRatesSuccess(employees_by_pk));
} else {
yield put(employeeGetRatesFailure(error));
}
} catch (error) {
yield put(employeeGetRatesFailure(error));
console.log("Error while getting employee rates.", error);
Sentry.Native.captureException(error);
//Sentry.Native.captureException(error);
}
}
export function* employeeSagas() {
yield all([call(onSignInEmployeeStart), call(employeeGetRatesSuccess)]);
yield all([call(onSignInEmployeeStart), call(onEmployeeSignInSuccessSaga), call(onEmployeeGetRatesStart)]);
}

View File

@@ -16,7 +16,7 @@ export const selectSignInError = createSelector(
);
export const selectRates = createSelector(
[selectEmployee],
(employee) => employee.currentEmployee.rates
(employee) => employee.currentEmployee.technician.rates
);
export const selectGettingRates = createSelector(
[selectEmployee],