Skip to content

Commit

Permalink
Merge pull request #182 from Vincit/fix/fix-duplicate-booking-duratio…
Browse files Browse the repository at this point in the history
…n-display

Fix for duplicate display for booking duration
  • Loading branch information
JBergVincit authored Jul 24, 2024
2 parents 19c1330 + baf12c7 commit 5c93fed
Showing 1 changed file with 6 additions and 68 deletions.
74 changes: 6 additions & 68 deletions frontend/src/components/RoomCard/RoomCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ export function getBookingTimeLeft(booking: Booking | undefined) {
if (booking === undefined) {
return 0;
}
return Math.ceil(getTimeLeftMinutes(booking.endTime)) + 2;
// If the booking is ongoing, i.e start time is before "now", then do getTimeLeftMinutes
// Otherwise just get the total duration of the booking
return DateTime.fromISO(booking.startTime) <= DateTime.now()
? Math.ceil(getTimeLeftMinutes(booking.endTime)) + 2
: getTimeDiff(booking.startTime, booking.endTime);
}

export function getTimeAvailableMinutes(booking: Booking | undefined) {
Expand Down Expand Up @@ -344,10 +348,7 @@ const ReservationStatusText = (props: {
<Stack direction={'row'}>
<RoomCardReservationStatusIndicator
reserved={props.reserved}
reservationTime={getTimeDiff(
props.booking?.startTime!,
props.booking?.endTime!
)}
reservationTime={getBookingTimeLeft(props.booking)}
/>
</Stack>
<Typography>
Expand Down Expand Up @@ -460,64 +461,6 @@ const RoomCard = (props: RoomCardProps) => {
return defaultVars;
};

const bookingTime = () => {
if (isReserved) {
if (booking?.resourceStatus === 'accepted') {
if (DateTime.fromISO(booking.startTime) <= DateTime.now()) {
return (
<StartBox>
<CheckCircleIcon color="success" fontSize="small" />
<Typography
id={'booked-to-you-label'}
aria-label={'Booked to you'}
variant="subtitle1"
color="success.main"
margin={'0 0 0 5px'}
>
Booked to you for {getBookingTimeLeft(booking)}{' '}
minutes.
</Typography>
</StartBox>
);
} else {
return (
<StartBox>
<CheckCircleIcon color="success" fontSize="small" />
<Typography
id={'booked-to-you-label'}
aria-label={'Booked to you'}
variant="subtitle1"
color="success.main"
margin={'0 0 0 5px'}
>
Booked to you for{' '}
{getTimeDiff(
booking.startTime,
booking.endTime
)}{' '}
minutes.
</Typography>
</StartBox>
);
}
} else {
return (
<StartBox>
<PendingIcon color="warning" fontSize="small" />
<Typography
variant="subtitle1"
color="warning.main"
margin={'0 0 0 5px'}
>
Waiting Google calendar confirmation.
</Typography>
</StartBox>
);
}
}
return null;
};

return (
<CustomCard data-testid="AvailableRoomListCard" style={cardStyle()}>
<CardActionArea
Expand All @@ -533,11 +476,6 @@ const RoomCard = (props: RoomCardProps) => {
/>
<RoomCardCapacityBox busy={isBusy} room={room} />
</Row>

<Typography aria-labelledby={'booked-to-you-label'}>
{bookingTime()}
</Typography>

<Row>
<Stack direction={'column'}>
<ReservationStatusText
Expand Down

0 comments on commit 5c93fed

Please sign in to comment.