Skip to content

Commit

Permalink
update: backend reservation types
Browse files Browse the repository at this point in the history
  • Loading branch information
joonatank committed Jan 21, 2025
1 parent 9b030a6 commit 2b417b1
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 886 deletions.
215 changes: 35 additions & 180 deletions apps/admin-ui/gql/gql-types.ts

Large diffs are not rendered by default.

23 changes: 8 additions & 15 deletions apps/admin-ui/src/component/EditTimeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
useCreateStaffReservationMutation,
useStaffAdjustReservationTimeMutation,
type ReservationQuery,
ReservationStaffCreateMutationInput,
} from "@gql/gql-types";
import { FormProvider, UseFormReturn, useForm } from "react-hook-form";
import { differenceInMinutes, format } from "date-fns";
Expand Down Expand Up @@ -315,7 +314,7 @@ export function NewReservationModal({
const { isOpen } = useModal();

const { recurringReservation, type } = reservationToCopy ?? {};
const { pk: recurringReservationPk } = recurringReservation ?? {};
// const { pk: recurringReservationPk } = recurringReservation ?? {};
const reservationUnit = reservationToCopy?.reservationUnits?.[0];

// NOTE 0 => buffer disabled for this reservation, undefined => no buffers selected
Expand Down Expand Up @@ -343,11 +342,7 @@ export function NewReservationModal({
// but do we need to pass in also the metadata? i.e. copy all the fields from another reservation?
const [create] = useCreateStaffReservationMutation();

function createInput({
begin,
end,
buffers,
}: MutationValues): ReservationStaffCreateMutationInput {
function createInput({ begin, end, buffers }: MutationValues) {
if (reservationToCopy == null) {
throw new Error("reservationToCopy missing");
}
Expand Down Expand Up @@ -391,11 +386,11 @@ export function NewReservationModal({
purposePk,
ageGroupPk,
...convertToApiFormat(begin, end),
bufferTimeAfter: String(buffers.after),
bufferTimeBefore: String(buffers.before),
reservationUnitPks: [reservationUnit?.pk],
bufferTimeAfter: buffers.after,
bufferTimeBefore: buffers.before,
reservationUnit: reservationUnit.pk,
type,
recurringReservationPk,
recurringReservation,
};
}

Expand Down Expand Up @@ -498,10 +493,8 @@ export function EditTimeModal({
input: {
...convertToApiFormat(begin, end),
pk,
bufferTimeAfter:
buffers.after != null ? String(buffers.after) : undefined,
bufferTimeBefore:
buffers.before != null ? String(buffers.before) : undefined,
bufferTimeAfter: buffers.after ?? undefined,
bufferTimeBefore: buffers.before ?? undefined,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,12 @@ function DialogContent({
? (reservationUnit.bufferTimeAfter ?? 0)
: 0;
const input: ReservationStaffCreateMutationInput = {
reservationUnitPks: [reservationUnit.pk],
reservationUnit: reservationUnit.pk,
type: values.type,
begin: dateTime(values.date, values.startTime),
end: dateTime(values.date, values.endTime),
bufferTimeBefore: bufferBefore.toString(),
bufferTimeAfter: bufferAfter.toString(),
bufferTimeBefore: bufferBefore,
bufferTimeAfter: bufferAfter,
workingMemo: values.comments,
...flatMetaValues,
reserveeType: values.reserveeType,
Expand Down
26 changes: 12 additions & 14 deletions apps/admin-ui/src/spa/reservations/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import {
ReserveeType,
CustomerTypeChoice,
type Maybe,
type ReservationStaffModifyMutationInput,
type UpdateStaffReservationMutationVariables,
} from "@gql/gql-types";
import { errorToast, successToast } from "common/src/common/toast";

export type MutationInputParams = Omit<
ReservationStaffModifyMutationInput,
"pk"
> & {
seriesName?: string;
workingMemo?: string;
};
type InputT = UpdateStaffReservationMutationVariables["input"];
type MemoT = Partial<UpdateStaffReservationMutationVariables["workingMemo"]>;
type ExtraParamsT = { seriesName?: string };

export type MutationInputParams = Omit<InputT, "pk"> &
Omit<MemoT, "pk"> &
ExtraParamsT;
type ReservationType = NonNullable<ReservationQuery["reservation"]>;

/// Combines regular and recurring reservation change mutation
Expand Down Expand Up @@ -50,21 +50,18 @@ export function useStaffReservationMutation({

try {
if (reservation.recurringReservation?.pk != null) {
const { purposePk, ageGroupPk, homeCityPk, type, ...details } = rest;
const { type, ...details } = rest;
const reserveeType = convertReserveeType(rest.reserveeType);
const reservationDetails = {
...details,
purpose: purposePk,
ageGroup: ageGroupPk,
homeCity: homeCityPk,
reserveeType,
};

const input: ReservationSeriesUpdateMutationInput = {
name: seriesName,
pk: reservation.recurringReservation.pk,
description: workingMemo,
ageGroup: rest.ageGroupPk,
ageGroup: rest.ageGroup,
reservationDetails,
};
const res = await recurringMutation({
Expand All @@ -89,7 +86,8 @@ export function useStaffReservationMutation({
},
workingMemo: {
pk: reservation.pk,
workingMemo,
// TODO this is not good we should either not update the working memo or always send the original value as default
workingMemo: workingMemo ?? "",
},
};
mutation({ variables });
Expand Down
Loading

0 comments on commit 2b417b1

Please sign in to comment.