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

Commit 4317d55

Browse files
committed
fix: login and reserve wrong time format
1 parent 22c85e6 commit 4317d55

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

apps/ui/pages/reservation-unit/[id].tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -862,14 +862,16 @@ const ReservationUnit = ({
862862
console.warn("not reservable because: ", reason);
863863
}
864864

865-
const [storedReservation, setStoredReservation, _removeStoredReservation] =
865+
const [storedReservation, setStoredReservation] =
866866
useLocalStorage<PendingReservation>("reservation");
867867
const storeReservationForLogin = useCallback(() => {
868868
if (reservationUnit.pk != null && focusSlot != null) {
869869
const { start, end } = focusSlot ?? {};
870+
// NOTE the only place where we use ISO strings since they are always converted to Date objects
871+
// another option would be to refactor storaged reservation to use Date objects
870872
setStoredReservation({
871-
begin: toUIDate(start),
872-
end: toUIDate(end),
873+
begin: start.toISOString(),
874+
end: end.toISOString(),
873875
price: undefined,
874876
reservationUnitPk: reservationUnit.pk ?? 0,
875877
});
@@ -900,17 +902,18 @@ const ReservationUnit = ({
900902
}, []);
901903

902904
useEffect(() => {
903-
const start = storedReservation?.begin
904-
? new Date(storedReservation.begin)
905-
: null;
906-
const end = storedReservation?.end ? new Date(storedReservation.end) : null;
907-
908-
if (start && end) {
909-
handleCalendarEventChange({
910-
start,
911-
end,
912-
} as CalendarEvent<ReservationNode>);
905+
const { begin, end } = storedReservation ?? {};
906+
if (begin == null || end == null) {
907+
return;
913908
}
909+
910+
const beginDate = new Date(begin);
911+
const endDate = new Date(end);
912+
913+
handleCalendarEventChange({
914+
start: beginDate,
915+
end: endDate,
916+
});
914917
// eslint-disable-next-line react-hooks/exhaustive-deps
915918
}, [storedReservation?.begin, storedReservation?.end]);
916919

0 commit comments

Comments
 (0)