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: Changed a notification to correctly mention time deduction during booking time change #178

Merged
Show file tree
Hide file tree
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
18 changes: 9 additions & 9 deletions frontend/src/components/CurrentBooking/AlterBookingDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ const AlterBookingDrawer = (props: Props) => {
const text: string = 'Hello World! I shared this content via Web Share';
const url: string | undefined = booking?.meetingLink;

const handleAdditionalTime = (minutes: number) => {
if (booking === undefined) {
const handleAlterTime = (minutes: number) => {
if (booking === undefined || minutes == 0) {
return;
}
onAlterTime(booking, minutes);
Expand All @@ -111,7 +111,7 @@ const AlterBookingDrawer = (props: Props) => {
const minutes = Math.floor(
nextHalfHour().diff(timeNow, 'minute').minutes
);
handleAdditionalTime(minutes - duration);
handleAlterTime(minutes - duration);
};

const nextHalfHour = () => {
Expand Down Expand Up @@ -175,7 +175,7 @@ const AlterBookingDrawer = (props: Props) => {
const minutes = Math.floor(
nextFullHour().diff(timeNow, 'minute').minutes
);
handleAdditionalTime(minutes - duration);
handleAlterTime(minutes - duration);
};

const disableNextFullHour = () => {
Expand Down Expand Up @@ -208,20 +208,20 @@ const AlterBookingDrawer = (props: Props) => {
return;
}
if (timeNow.hour >= LAST_HOUR) {
handleAdditionalTime(availableMinutes - 1);
handleAlterTime(availableMinutes - 1);
} else {
const time1700 = DateTime.fromObject({ hour: LAST_HOUR });
const endTime = checkStartingTime().plus({
minutes: availableMinutes
});
if (endTime < time1700) {
return handleAdditionalTime(availableMinutes);
return handleAlterTime(availableMinutes);
}
const minutes = time1700.diff(
DateTime.fromISO(booking?.endTime),
'minutes'
).minutes;
handleAdditionalTime(Math.floor(minutes));
handleAlterTime(Math.floor(minutes));
}
};

Expand Down Expand Up @@ -315,7 +315,7 @@ const AlterBookingDrawer = (props: Props) => {
<DrawerButtonPrimary
aria-label="subtract 15 minutes"
data-testid="subtract15"
onClick={() => handleAdditionalTime(-15)}
onClick={() => handleAlterTime(-15)}
disabled={disableSubtractTime()}
>
<RemoveIcon /> 15 min
Expand All @@ -324,7 +324,7 @@ const AlterBookingDrawer = (props: Props) => {
<DrawerButtonPrimary
aria-label="add 15 minutes"
data-testid="add15"
onClick={() => handleAdditionalTime(15)}
onClick={() => handleAlterTime(15)}
disabled={disableAddTime()}
>
<AddIcon /> 15 min
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/components/CurrentBooking/CurrentBooking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ const CurrentBooking = (props: CurrentBookingProps) => {
setSelectedId(room.id);
toggleDrawer(true);
};
// Add extra time for the reserved room
const handleAddExtraTime = (booking: Booking, minutes: number) => {

// Add or subtract time from the current booking
const handleAlterTime = (booking: Booking, minutes: number) => {
let addTimeDetails: AddTimeDetails = {
timeToAdd: minutes
};
Expand All @@ -105,7 +106,11 @@ const CurrentBooking = (props: CurrentBookingProps) => {
setBookingProcessing('false');
// replace updated booking
updateBookings();
createSuccessNotification('Time added to booking');
const timeAlterNotification =
minutes > 0
? 'Time added to booking'
: 'Time deducted from booking';
createSuccessNotification(timeAlterNotification);
window.scrollTo(0, 0);
})
.catch(() => {
Expand Down Expand Up @@ -163,7 +168,7 @@ const CurrentBooking = (props: CurrentBookingProps) => {
open={isOpenDrawer}
toggle={toggleDrawer}
duration={timeLeft(selectedBooking)}
onAlterTime={handleAddExtraTime}
onAlterTime={handleAlterTime}
availableMinutes={getTimeAvailableMinutes(selectedBooking)}
booking={selectedBooking}
endBooking={handleEndBooking}
Expand Down