Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for duplicate display for booking duration #182

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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