Fix booking success page crash when a booking doesnt have newly added required fields response
parent
c5cd57d8f4
commit
cdb5b4a9dd
|
@ -26,7 +26,7 @@ import {
|
|||
SystemField,
|
||||
} from "@calcom/features/bookings/lib/getBookingFields";
|
||||
import getBookingResponsesSchema, {
|
||||
getBookingResponsesQuerySchema,
|
||||
getBookingResponsesPartialSchema,
|
||||
} from "@calcom/features/bookings/lib/getBookingResponsesSchema";
|
||||
import { FormBuilderField } from "@calcom/features/form-builder/FormBuilder";
|
||||
import CustomBranding from "@calcom/lib/CustomBranding";
|
||||
|
@ -261,7 +261,7 @@ const BookingPage = ({
|
|||
const rescheduleUid = router.query.rescheduleUid as string;
|
||||
useTheme(profile.theme);
|
||||
const date = asStringOrNull(router.query.date);
|
||||
const querySchema = getBookingResponsesQuerySchema({
|
||||
const querySchema = getBookingResponsesPartialSchema({
|
||||
bookingFields: getBookingFieldsWithSystemFields(eventType),
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Prisma, PrismaClient } from "@prisma/client";
|
||||
import { z } from "zod";
|
||||
|
||||
import getBookingResponsesSchema from "@calcom/features/bookings/lib/getBookingResponsesSchema";
|
||||
import { getBookingResponsesPartialSchema } from "@calcom/features/bookings/lib/getBookingResponsesSchema";
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import { eventTypeBookingFields } from "@calcom/prisma/zod-utils";
|
||||
|
||||
|
@ -72,7 +72,7 @@ async function getBooking(
|
|||
}
|
||||
const booking = {
|
||||
...rawBooking,
|
||||
responses: getBookingResponsesSchema({
|
||||
responses: getBookingResponsesPartialSchema({
|
||||
bookingFields,
|
||||
}).parse(rawBooking.responses || getResponsesFromOldBooking(rawBooking)),
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@ import {
|
|||
SystemField,
|
||||
getBookingFieldsWithSystemFields,
|
||||
} from "@calcom/features/bookings/lib/getBookingFields";
|
||||
import getBookingResponsesSchema from "@calcom/features/bookings/lib/getBookingResponsesSchema";
|
||||
import { getBookingResponsesPartialSchema } from "@calcom/features/bookings/lib/getBookingResponsesSchema";
|
||||
import { parseRecurringEvent } from "@calcom/lib";
|
||||
import CustomBranding from "@calcom/lib/CustomBranding";
|
||||
import { APP_NAME } from "@calcom/lib/constants";
|
||||
|
@ -1029,7 +1029,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
|||
|
||||
const bookingInfo = {
|
||||
...bookingInfoRaw,
|
||||
responses: getBookingResponsesSchema(eventTypeRaw).parse(bookingInfoRaw.responses),
|
||||
responses: getBookingResponsesPartialSchema(eventTypeRaw).parse(bookingInfoRaw.responses),
|
||||
};
|
||||
|
||||
// @NOTE: had to do this because Server side cant return [Object objects]
|
||||
|
|
|
@ -4,12 +4,15 @@ import z from "zod";
|
|||
import { bookingResponses, eventTypeBookingFields } from "@calcom/prisma/zod-utils";
|
||||
|
||||
type EventType = Parameters<typeof preprocess>[0]["eventType"];
|
||||
export const getBookingResponsesQuerySchema = (eventType: EventType) => {
|
||||
export const getBookingResponsesPartialSchema = (eventType: EventType) => {
|
||||
const schema = bookingResponses.unwrap().partial().and(z.record(z.any()));
|
||||
|
||||
return preprocess({ schema, eventType, forQueryParsing: true });
|
||||
};
|
||||
|
||||
// Should be used when we know that not all fields responses are present
|
||||
// - Can happen when we are parsing the prefill query string
|
||||
// - Can happen when we are parsing a booking's responses (which was created before we added a new required field)
|
||||
export default function getBookingResponsesSchema(eventType: EventType) {
|
||||
const schema = bookingResponses.and(z.record(z.any()));
|
||||
return preprocess({ schema, eventType, forQueryParsing: false });
|
||||
|
|
Loading…
Reference in New Issue