Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 3e5f8be

Browse files
committed
review fixes
1 parent 15bc342 commit 3e5f8be

13 files changed

Lines changed: 286 additions & 378 deletions

File tree

apps/ui/components/calendar/ReservationCalendarControls.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,7 @@ function ReservationCalendarControls({
420420
{mode === "edit" && (
421421
<SelectButton
422422
onClick={() => {
423-
/* FIXME setValue doesn't work for some reason
424-
* controllers do work
425-
* */
426-
const value = !areControlsVisible;
427-
setValue("isControlsVisible", value, {
423+
setValue("isControlsVisible", !areControlsVisible, {
428424
shouldDirty: true,
429425
shouldValidate: true,
430426
shouldTouch: true,

apps/ui/components/reservation-unit/utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ export function getNextAvailableTime(props: AvailableTimesProps): Date | null {
121121
const { reservationsMinDaysBefore, reservationsMaxDaysBefore } =
122122
reservationUnit;
123123

124-
const today = addDays(new Date(), reservationsMinDaysBefore ?? 0);
124+
const minReservationDate = addDays(
125+
new Date(),
126+
reservationsMinDaysBefore ?? 0
127+
);
125128
const possibleEndDay = getLastPossibleReservationDate(reservationUnit);
126129
const endDay = possibleEndDay ? addDays(possibleEndDay, 1) : undefined;
127130
// NOTE there is still a case where application rounds have a hole but there are no reservable times
@@ -134,7 +137,7 @@ export function getNextAvailableTime(props: AvailableTimesProps): Date | null {
134137
}
135138
const end = new Date(round.reservationPeriodEnd);
136139
const begin = new Date(round.reservationPeriodBegin);
137-
if (isBefore(end, today)) {
140+
if (isBefore(end, minReservationDate)) {
138141
return acc;
139142
}
140143
if (acc == null) {
@@ -146,7 +149,8 @@ export function getNextAvailableTime(props: AvailableTimesProps): Date | null {
146149
}
147150
return dayMax([acc, new Date(round.reservationPeriodEnd)]);
148151
}, undefined);
149-
const minDay = dayMax([today, start, openAfterRound]) ?? today;
152+
const minDay =
153+
dayMax([minReservationDate, start, openAfterRound]) ?? minReservationDate;
150154

151155
// Find the first possible day
152156
let openTimes = reservableTimes.get(dateToKey(minDay));

apps/ui/components/reservation/EditStep0.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,6 @@ export function EditStep0({
349349
}
350350
};
351351

352-
// TODO skip length check is weird, why was it needed here?
353-
// it allows selecting too long reservations and disables the next button
354352
const handleCalendarEventChange = useCallback(
355353
({ start, end }: CalendarEvent<ReservationNode>): boolean => {
356354
const { start: newStart, end: newEnd } =

apps/ui/modules/__tests__/reservable.test.ts

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
type RoundPeriod,
1212
generateReservableMap,
1313
isRangeReservable,
14-
getDayIntervals,
1514
isStartTimeValid,
1615
} from "../reservable";
1716
import {
@@ -752,111 +751,3 @@ describe("isRangeReservable", () => {
752751
expect(isRangeReservable(input)).toBe(true);
753752
});
754753
});
755-
756-
describe("getDayIntervals", () => {
757-
test("getDayIntervals from 9 to 17 with 30 min interval", () => {
758-
const input = {
759-
startTime: { h: 9, m: 0 },
760-
endTime: { h: 17, m: 0 },
761-
interval: ReservationStartInterval.Interval_30Mins,
762-
};
763-
const output: { h: number; m: number }[] = [];
764-
for (let i = 9; i < 17; i++) {
765-
output.push({ h: i, m: 0 });
766-
output.push({ h: i, m: 30 });
767-
}
768-
const res = getDayIntervals(input.startTime, input.endTime, input.interval);
769-
expect(res).toEqual(output);
770-
});
771-
test("getDayIntervals from 9 to 17 with 15 min interval", () => {
772-
const input = {
773-
startTime: { h: 9, m: 0 },
774-
endTime: { h: 17, m: 0 },
775-
interval: ReservationStartInterval.Interval_15Mins,
776-
};
777-
const output: { h: number; m: number }[] = [];
778-
for (let i = 9; i < 17; i++) {
779-
output.push({ h: i, m: 0 });
780-
output.push({ h: i, m: 15 });
781-
output.push({ h: i, m: 30 });
782-
output.push({ h: i, m: 45 });
783-
}
784-
const res = getDayIntervals(input.startTime, input.endTime, input.interval);
785-
expect(res).toEqual(output);
786-
});
787-
test("getDayIntervals from 9 to 17 with 60 min interval", () => {
788-
const input = {
789-
startTime: { h: 9, m: 0 },
790-
endTime: { h: 17, m: 0 },
791-
interval: ReservationStartInterval.Interval_60Mins,
792-
};
793-
const output: { h: number; m: number }[] = [];
794-
for (let i = 9; i < 17; i++) {
795-
output.push({ h: i, m: 0 });
796-
}
797-
const res = getDayIntervals(input.startTime, input.endTime, input.interval);
798-
expect(res).toEqual(output);
799-
});
800-
test("getDayIntervals from 0 to 24 with 30 min interval", () => {
801-
const input = {
802-
startTime: { h: 0, m: 0 },
803-
endTime: { h: 24, m: 0 },
804-
interval: ReservationStartInterval.Interval_30Mins,
805-
};
806-
const output: { h: number; m: number }[] = [];
807-
for (let i = 0; i < 24; i++) {
808-
output.push({ h: i, m: 0 });
809-
output.push({ h: i, m: 30 });
810-
}
811-
const res = getDayIntervals(input.startTime, input.endTime, input.interval);
812-
expect(res).toEqual(output);
813-
});
814-
test("getDayIntervals with invalid range", () => {
815-
const input = {
816-
startTime: { h: 17, m: 0 },
817-
endTime: { h: 9, m: 0 },
818-
interval: ReservationStartInterval.Interval_30Mins,
819-
};
820-
const res = getDayIntervals(input.startTime, input.endTime, input.interval);
821-
expect(res).toEqual([]);
822-
});
823-
test("getDayIntervals with 0 size range", () => {
824-
const input = {
825-
startTime: { h: 17, m: 0 },
826-
endTime: { h: 17, m: 0 },
827-
interval: ReservationStartInterval.Interval_30Mins,
828-
};
829-
const res = getDayIntervals(input.startTime, input.endTime, input.interval);
830-
expect(res).toEqual([]);
831-
});
832-
test("getDayIntervals with uneven times", () => {
833-
const input = {
834-
startTime: { h: 9, m: 20 },
835-
endTime: { h: 17, m: 20 },
836-
interval: ReservationStartInterval.Interval_30Mins,
837-
};
838-
const output: { h: number; m: number }[] = [];
839-
for (let i = 9; i < 17; i++) {
840-
output.push({ h: i, m: 20 });
841-
output.push({ h: i, m: 50 });
842-
}
843-
const res = getDayIntervals(input.startTime, input.endTime, input.interval);
844-
expect(res).toEqual(output);
845-
});
846-
test("getDayIntervals with uneven times", () => {
847-
const input = {
848-
startTime: { h: 9, m: 20 },
849-
endTime: { h: 17, m: 0 },
850-
interval: ReservationStartInterval.Interval_30Mins,
851-
};
852-
const output: { h: number; m: number }[] = [];
853-
for (let i = 9; i < 17; i++) {
854-
output.push({ h: i, m: 20 });
855-
if (i < 16) {
856-
output.push({ h: i, m: 50 });
857-
}
858-
}
859-
const res = getDayIntervals(input.startTime, input.endTime, input.interval);
860-
expect(res).toEqual(output);
861-
});
862-
});

0 commit comments

Comments
 (0)