diff --git a/frontend/src/components/UserTables/RidesTable.tsx b/frontend/src/components/UserTables/RidesTable.tsx index e78f95489..527c093fc 100644 --- a/frontend/src/components/UserTables/RidesTable.tsx +++ b/frontend/src/components/UserTables/RidesTable.tsx @@ -8,6 +8,7 @@ import styles from './table.module.css'; import { useEmployees } from '../../context/EmployeesContext'; import DeleteOrEditTypeModal from '../Modal/DeleteOrEditTypeModal'; import { trashbig } from '../../icons/other/index'; +import { DriverType } from '../../../../server/src/models/driver'; type RidesTableProps = { rides: Ride[]; @@ -44,6 +45,20 @@ const RidesTable = ({ rides, hasButtons }: RidesTableProps) => { '', ]; + // hasConflict(rides, newRide) is true if and only if the driver of the new ride has a conflict (Date object time-overlap) + // with an existing ride in the table (which is represented as array of rides). + function hasConflict(rides: Ride[], newRide: Ride): boolean { + return rides.some((ride) => { + return ( + ride.driver === newRide.driver && + ((new Date(newRide.startTime) >= new Date(ride.startTime) && + new Date(newRide.startTime) < new Date(ride.endTime)) || + (new Date(newRide.endTime) > new Date(ride.startTime) && + new Date(newRide.endTime) <= new Date(ride.endTime))) + ); + }); + } + return ( <> @@ -85,18 +100,26 @@ const RidesTable = ({ rides, hasButtons }: RidesTableProps) => { ), }; - const assignButton = (shouldReassign: boolean) => ( - - ); + const assignButton = (shouldReassign: boolean, newRide: Ride) => { + return ( + + ); + }; const editButton = (