From 20e59bdd6b644979556563e4bbb296733d1d90f2 Mon Sep 17 00:00:00 2001 From: jfrye122 Date: Fri, 2 Jun 2023 13:34:42 -0400 Subject: [PATCH] update Employee field to show first and last name --- .../screen-time-ticket-create.component.jsx | 5 +- redux/employee/employee.selectors.js | 49 ++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/components/time-ticket/screen-time-ticket-create.component.jsx b/components/time-ticket/screen-time-ticket-create.component.jsx index 82a965b..449cbe5 100644 --- a/components/time-ticket/screen-time-ticket-create.component.jsx +++ b/components/time-ticket/screen-time-ticket-create.component.jsx @@ -11,6 +11,7 @@ import DateTimePickerModal from "react-native-modal-datetime-picker"; import { selectCurrentEmployee, selectRates, + selectEmployeeFullName } from "../../redux/employee/employee.selectors"; import { selectBodyshop } from "../../redux/user/user.selectors"; import { useCallback } from "react"; @@ -29,6 +30,7 @@ const mapStateToProps = createStructuredSelector({ currentEmployee: selectCurrentEmployee, currentRatesNCostCenters: selectRates, currentBodyshop: selectBodyshop, + currentEmployeeFullName: selectEmployeeFullName }); // const mapDispatchToProps = (dispatch) => ({}); @@ -36,6 +38,7 @@ export function TimeTicketCreate({ currentEmployee, currentRatesNCostCenters, currentBodyshop, + currentEmployeeFullName }) { const navigation = useNavigation(); const { t } = useTranslation(); @@ -183,7 +186,7 @@ export function TimeTicketCreate({ initialValues={{ jobid: { currentSJobId }, ticketdate: date2.toLocaleDateString(), - employee: currentEmployee.technician.first_name, + employee: {currentEmployeeFullName}, costcenter: { currentSCC }, productivehours: "", actualhours: "", diff --git a/redux/employee/employee.selectors.js b/redux/employee/employee.selectors.js index 00def96..1818289 100644 --- a/redux/employee/employee.selectors.js +++ b/redux/employee/employee.selectors.js @@ -24,5 +24,52 @@ export const selectGettingRates = createSelector( ); export const selectTechnician = createSelector( [selectEmployee], - (employee) => employee.currentEmployee?.technician + (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; + } + } );