diff --git a/client/src/components/trans-routes/RoutesSection.js b/client/src/components/trans-routes/RoutesSection.js index 3edcbb2..4a89d15 100644 --- a/client/src/components/trans-routes/RoutesSection.js +++ b/client/src/components/trans-routes/RoutesSection.js @@ -18,13 +18,19 @@ const RoutesSection = ({transRoutes, copyList, sectionName, drivers, vehicles, c const params = new URLSearchParams(window.location.search); const scheduleDate = params.get('dateSchedule'); + const normalizeCustomerType = (value) => `${value || ''}`.trim().toLowerCase().replace(/\s+/g, '_'); + const isMemberLikeType = (value) => [CUSTOMER_TYPE.MEMBER, CUSTOMER_TYPE.SELF_PAY].includes(normalizeCustomerType(value)); + const isVisitorType = (value) => normalizeCustomerType(value) === CUSTOMER_TYPE.VISITOR; + useEffect(() => { const getSeniors = () => { const seniors = []; if (transRoutes) { for (const transRoute of transRoutes) { for (const customer of transRoute.route_customer_list) { - if (!seniors.includes(customer.customer_id) && customer.customer_pickup_status !== PICKUP_STATUS.SCHEDULE_ABSENT && customer.customer_route_status !== PERSONAL_ROUTE_STATUS.DISABLED) { + const customerId = customer?.customer_id; + const hasSameCustomer = seniors.some((item) => item?.customer_id === customerId); + if (!hasSameCustomer && customer.customer_pickup_status !== PICKUP_STATUS.SCHEDULE_ABSENT && customer.customer_route_status !== PERSONAL_ROUTE_STATUS.DISABLED) { seniors.push(customer); } } @@ -93,7 +99,7 @@ const RoutesSection = ({transRoutes, copyList, sectionName, drivers, vehicles, c {`${sectionName}: `} { (sectionName.includes('Inbound') || sectionName.includes('Outbound')) && - (`${seniors.filter(item => [CUSTOMER_TYPE.MEMBER, CUSTOMER_TYPE.SELF_PAY].includes(item.customer_type) && ![PERSONAL_ROUTE_STATUS.UNEXPECTED_ABSENT, PERSONAL_ROUTE_STATUS.SCHEDULED_ABSENT].includes(item?.customer_route_status))?.length} Members ${seniors.filter(item=> [CUSTOMER_TYPE.VISITOR].includes(item?.customer_type) && ![PERSONAL_ROUTE_STATUS.UNEXPECTED_ABSENT, PERSONAL_ROUTE_STATUS.SCHEDULED_ABSENT].includes(item?.customer_route_status))?.length} Visitors${sectionName.includes('Inbound') && showCheckedInText ? ` ${seniors.filter(item => item?.customer_route_status === PERSONAL_ROUTE_STATUS.IN_CENTER)?.length} checked in` : ''}`)} + (`${seniors.filter(item => isMemberLikeType(item?.customer_type) && ![PERSONAL_ROUTE_STATUS.UNEXPECTED_ABSENT, PERSONAL_ROUTE_STATUS.SCHEDULED_ABSENT].includes(item?.customer_route_status))?.length} Members ${seniors.filter(item=> isVisitorType(item?.customer_type) && ![PERSONAL_ROUTE_STATUS.UNEXPECTED_ABSENT, PERSONAL_ROUTE_STATUS.SCHEDULED_ABSENT].includes(item?.customer_route_status))?.length} Visitors${sectionName.includes('Inbound') && showCheckedInText ? ` ${seniors.filter(item => item?.customer_route_status === PERSONAL_ROUTE_STATUS.IN_CENTER)?.length} checked in` : ''}`)}