Files
imexmobile/redux/employee/employee.selectors.js

76 lines
2.2 KiB
JavaScript

import { createSelector } from "reselect";
const selectEmployee = (state) => state.employee;
export const selectCurrentEmployee = createSelector(
[selectEmployee],
(employee) => employee.currentEmployee
);
export const selectSigningIn = createSelector(
[selectEmployee],
(employee) => employee.signingIn
);
export const selectSignInError = createSelector(
[selectEmployee],
(employee) => employee.error
);
export const selectRates = createSelector(
[selectEmployee],
(employee) => employee.currentEmployee?.technician?.rates?.filter((v) => (v?.cost_center !== "timetickets.labels.shift"))
);
export const selectGettingRates = createSelector(
[selectEmployee],
(employee) => employee.gettingRates
);
export const selectTechnician = createSelector(
[selectEmployee],
(employee) => {
if (!employee.currentEmployee || !employee.currentEmployee.technician) {
// console.info("selectTechnician returning null");
return null;
}
// console.info("selectTechnician returning :", employee.currentEmployee.technician);
return employee.currentEmployee.technician;
}
);
export const selectEmployeeFirstName = createSelector(
[selectTechnician],
(techResults) => {
if (!techResults || !techResults.first_name) {
// console.info("selectEmployeeFirstName returning null");
return null;
}
// console.info("selectEmployeeFirstName returning :", techResults.first_name);
return techResults.first_name;
}
);
export const selectEmployeeLastName = createSelector(
[selectTechnician],
(techResults) => {
if (!techResults || !techResults.last_name) {
// console.info("selectEmployeeLastName returning null");
return null;
}
// console.info("selectEmployeeLastName returning :", techResults.last_name);
return techResults.last_name;
}
);
export const selectEmployeeFullName = createSelector(
[selectEmployeeFirstName,selectEmployeeLastName],
(fName,lName) => {
if (!fName && !lName) {
// console.warn("selectEmployeeFullName returning null");
return null;
}
if (fName) {
if(lName){
return fName + " " + lName;
} else {
return fName;
}
} else {
return lName;
}
}
);