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 22, 2025
1 parent 9b030a6 commit f58be29
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 889 deletions.
215 changes: 35 additions & 180 deletions apps/admin-ui/gql/gql-types.ts

Large diffs are not rendered by default.

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

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

// NOTE 0 => buffer disabled for this reservation, undefined => no buffers selected
Expand Down Expand Up @@ -375,9 +374,9 @@ export function NewReservationModal({
"reserveeOrganisationName",
"reserveePhone",
] as const;
const homeCityPk = reservationToCopy.homeCity?.pk;
const purposePk = reservationToCopy.purpose?.pk;
const ageGroupPk = reservationToCopy.ageGroup?.pk;
const homeCity = reservationToCopy.homeCity?.pk;
const purpose = reservationToCopy.purpose?.pk;
const ageGroup = reservationToCopy.ageGroup?.pk;
const metadata = pick(reservationToCopy, keys);
if (!reservationUnit?.pk) {
throw new Error("reservation unit pk missing");
Expand All @@ -387,15 +386,14 @@ export function NewReservationModal({
}
return {
...metadata,
homeCityPk,
purposePk,
ageGroupPk,
...convertToApiFormat(begin, end),
bufferTimeAfter: String(buffers.after),
bufferTimeBefore: String(buffers.before),
reservationUnitPks: [reservationUnit?.pk],
homeCity,
purpose,
ageGroup,
bufferTimeAfter: buffers.after,
bufferTimeBefore: buffers.before,
reservationUnit: reservationUnit.pk,
type,
recurringReservationPk,
};
}

Expand Down Expand Up @@ -498,10 +496,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
2 changes: 1 addition & 1 deletion apps/admin-ui/src/schemas/reservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const ReservationChangeFormSchema = z
.object({
type: ReservationTypeSchema,
seriesName: z.string().optional(),
comments: z.string().optional(),
comments: z.string(),
showBillingAddress: z.boolean().optional(),
})
// passthrough since this is combined to the metafields
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
2 changes: 1 addition & 1 deletion apps/admin-ui/src/spa/reservations/[id]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function EditReservation({
mode: "onChange",
defaultValues: {
seriesName: reservation.recurringReservation?.name ?? "",
comments: reservation.workingMemo ?? undefined,
comments: reservation.workingMemo ?? "",
type: ReservationTypeSchema.optional().parse(
reservation.type?.toUpperCase()
),
Expand Down
23 changes: 10 additions & 13 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 = 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 Down
Loading

0 comments on commit f58be29

Please sign in to comment.