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

Commit 9ca473e

Browse files
committed
fix: recurring reservation collision checks
1 parent 1350ed3 commit 9ca473e

5 files changed

Lines changed: 17 additions & 14 deletions

File tree

apps/admin-ui/src/component/my-units/ReservationUnitCalendar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getEventBuffers } from "common/src/calendar/util";
1717
import { reservationUrl } from "@/common/urls";
1818
import { useNotification } from "@/context/NotificationContext";
1919
import Legend from "../reservations/requested/Legend";
20-
import { RESERVATIONS_BY_RESERVATIONUNITS } from "./queries";
20+
import { RESERVATION_UNIT_CALENDAR_QUERY } from "./queries";
2121
import eventStyleGetter, { legend } from "./eventStyleGetter";
2222
import { PUBLIC_URL } from "@/common/const";
2323
import { getReserveeName } from "../reservations/requested/util";
@@ -96,7 +96,7 @@ export function ReservationUnitCalendar({
9696
const { data, loading: isLoading } = useQuery<
9797
Query,
9898
ReservationUnitWithAffectingArgs
99-
>(RESERVATIONS_BY_RESERVATIONUNITS, {
99+
>(RESERVATION_UNIT_CALENDAR_QUERY, {
100100
fetchPolicy: "network-only",
101101
skip: reservationUnitPk === 0,
102102
variables: {

apps/admin-ui/src/component/my-units/queries.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ export const RECURRING_RESERVATION_UNIT_QUERY = gql`
1717
}
1818
`;
1919

20-
export const RESERVATIONS_BY_RESERVATIONUNITS = gql`
20+
// TODO the fragments that this uses should be combined with the other tab page (my-units)
21+
// This is only used in the ReservationUnitCalendar component.
22+
export const RESERVATION_UNIT_CALENDAR_QUERY = gql`
2123
${RESERVATIONUNIT_RESERVATIONS_FRAGMENT}
22-
query ReservationUnitReservations(
24+
query ReservationUnitCalendar(
2325
$id: ID!
2426
$pk: Int!
2527
$state: [String]

apps/admin-ui/src/component/reservations/requested/hooks/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useQuery } from "@apollo/client";
1313
import { toApiDate } from "common/src/common/util";
1414
import {
1515
RECURRING_RESERVATION_QUERY,
16-
RESERVATIONS_BY_RESERVATIONUNIT,
16+
RESERVATIONS_BY_RESERVATIONUNITS,
1717
SINGLE_RESERVATION_QUERY,
1818
} from "./queries";
1919
import { useNotification } from "@/context/NotificationContext";
@@ -75,7 +75,7 @@ export function useReservationData(
7575
const typename = "ReservationUnitNode";
7676
const id = base64encode(`${typename}:${reservationUnitPk}`);
7777
const { data, ...rest } = useQuery<Query, ReservationUnitWithAffectingArgs>(
78-
RESERVATIONS_BY_RESERVATIONUNIT,
78+
RESERVATIONS_BY_RESERVATIONUNITS,
7979
{
8080
fetchPolicy: "no-cache",
8181
skip: !reservationUnitPk,

apps/admin-ui/src/component/reservations/requested/hooks/queries.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { gql } from "@apollo/client";
2-
32
import {
43
RESERVATION_COMMON_FRAGMENT,
54
RESERVATION_META_FRAGMENT,
@@ -22,16 +21,15 @@ const CALENDAR_RESERVATION_FRAGMENT = gql`
2221
type
2322
bufferTimeBefore
2423
bufferTimeAfter
25-
recurringReservation {
26-
pk
27-
}
2824
affectedReservationUnits
2925
}
3026
`;
3127

32-
export const RESERVATIONS_BY_RESERVATIONUNIT = gql`
28+
// TODO there is two versions of this query.
29+
// This is used in the hooks (collision checks).
30+
export const RESERVATIONS_BY_RESERVATIONUNITS = gql`
3331
${CALENDAR_RESERVATION_FRAGMENT}
34-
query reservationUnit(
32+
query ReservationsByReservationUnit(
3533
$id: ID!
3634
$pk: Int!
3735
$beginDate: Date
@@ -117,6 +115,9 @@ export const RECURRING_RESERVATION_QUERY = gql`
117115
begin
118116
end
119117
state
118+
reservationUnit {
119+
pk
120+
}
120121
}
121122
}
122123
}

apps/admin-ui/src/component/reservations/requested/hooks/useCheckCollisions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type Query, ReservationTypeChoice } from "common/types/gql-types";
22
import { useQuery } from "@apollo/client";
33
import { useNotification } from "@/context/NotificationContext";
44
import { doesIntervalCollide, reservationToInterval } from "@/helpers";
5-
import { RESERVATIONS_BY_RESERVATIONUNIT } from "./queries";
5+
import { RESERVATIONS_BY_RESERVATIONUNITS } from "./queries";
66
import {
77
base64encode,
88
concatAffectedReservations,
@@ -37,7 +37,7 @@ function useCheckCollisions({
3737
const typename = "ReservationUnitNode";
3838
const id = base64encode(`${typename}:${reservationUnitPk}`);
3939
const { data, loading } = useQuery<Query, ReservationUnitWithAffectingArgs>(
40-
RESERVATIONS_BY_RESERVATIONUNIT,
40+
RESERVATIONS_BY_RESERVATIONUNITS,
4141
{
4242
fetchPolicy: "no-cache",
4343
skip: !reservationUnitPk || !start || !end,

0 commit comments

Comments
 (0)