Skip to content

Commit

Permalink
fix: recurring reservation collision checks
Browse files Browse the repository at this point in the history
  • Loading branch information
joonatank committed Apr 25, 2024
1 parent 1350ed3 commit 9ca473e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getEventBuffers } from "common/src/calendar/util";
import { reservationUrl } from "@/common/urls";
import { useNotification } from "@/context/NotificationContext";
import Legend from "../reservations/requested/Legend";
import { RESERVATIONS_BY_RESERVATIONUNITS } from "./queries";
import { RESERVATION_UNIT_CALENDAR_QUERY } from "./queries";
import eventStyleGetter, { legend } from "./eventStyleGetter";
import { PUBLIC_URL } from "@/common/const";
import { getReserveeName } from "../reservations/requested/util";
Expand Down Expand Up @@ -96,7 +96,7 @@ export function ReservationUnitCalendar({
const { data, loading: isLoading } = useQuery<
Query,
ReservationUnitWithAffectingArgs
>(RESERVATIONS_BY_RESERVATIONUNITS, {
>(RESERVATION_UNIT_CALENDAR_QUERY, {
fetchPolicy: "network-only",
skip: reservationUnitPk === 0,
variables: {
Expand Down
6 changes: 4 additions & 2 deletions apps/admin-ui/src/component/my-units/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export const RECURRING_RESERVATION_UNIT_QUERY = gql`
}
`;

export const RESERVATIONS_BY_RESERVATIONUNITS = gql`
// TODO the fragments that this uses should be combined with the other tab page (my-units)
// This is only used in the ReservationUnitCalendar component.
export const RESERVATION_UNIT_CALENDAR_QUERY = gql`
${RESERVATIONUNIT_RESERVATIONS_FRAGMENT}
query ReservationUnitReservations(
query ReservationUnitCalendar(
$id: ID!
$pk: Int!
$state: [String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useQuery } from "@apollo/client";
import { toApiDate } from "common/src/common/util";
import {
RECURRING_RESERVATION_QUERY,
RESERVATIONS_BY_RESERVATIONUNIT,
RESERVATIONS_BY_RESERVATIONUNITS,
SINGLE_RESERVATION_QUERY,
} from "./queries";
import { useNotification } from "@/context/NotificationContext";
Expand Down Expand Up @@ -75,7 +75,7 @@ export function useReservationData(
const typename = "ReservationUnitNode";
const id = base64encode(`${typename}:${reservationUnitPk}`);
const { data, ...rest } = useQuery<Query, ReservationUnitWithAffectingArgs>(
RESERVATIONS_BY_RESERVATIONUNIT,
RESERVATIONS_BY_RESERVATIONUNITS,
{
fetchPolicy: "no-cache",
skip: !reservationUnitPk,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { gql } from "@apollo/client";

import {
RESERVATION_COMMON_FRAGMENT,
RESERVATION_META_FRAGMENT,
Expand All @@ -22,16 +21,15 @@ const CALENDAR_RESERVATION_FRAGMENT = gql`
type
bufferTimeBefore
bufferTimeAfter
recurringReservation {
pk
}
affectedReservationUnits
}
`;

export const RESERVATIONS_BY_RESERVATIONUNIT = gql`
// TODO there is two versions of this query.
// This is used in the hooks (collision checks).
export const RESERVATIONS_BY_RESERVATIONUNITS = gql`
${CALENDAR_RESERVATION_FRAGMENT}
query reservationUnit(
query ReservationsByReservationUnit(
$id: ID!
$pk: Int!
$beginDate: Date
Expand Down Expand Up @@ -117,6 +115,9 @@ export const RECURRING_RESERVATION_QUERY = gql`
begin
end
state
reservationUnit {
pk
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type Query, ReservationTypeChoice } from "common/types/gql-types";
import { useQuery } from "@apollo/client";
import { useNotification } from "@/context/NotificationContext";
import { doesIntervalCollide, reservationToInterval } from "@/helpers";
import { RESERVATIONS_BY_RESERVATIONUNIT } from "./queries";
import { RESERVATIONS_BY_RESERVATIONUNITS } from "./queries";
import {
base64encode,
concatAffectedReservations,
Expand Down Expand Up @@ -37,7 +37,7 @@ function useCheckCollisions({
const typename = "ReservationUnitNode";
const id = base64encode(`${typename}:${reservationUnitPk}`);
const { data, loading } = useQuery<Query, ReservationUnitWithAffectingArgs>(
RESERVATIONS_BY_RESERVATIONUNIT,
RESERVATIONS_BY_RESERVATIONUNITS,
{
fetchPolicy: "no-cache",
skip: !reservationUnitPk || !start || !end,
Expand Down

0 comments on commit 9ca473e

Please sign in to comment.