-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Send responses in confirm booking flow (#7830)
- Loading branch information
1 parent
04c634e
commit a8825ba
Showing
11 changed files
with
150 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type z from "zod"; | ||
|
||
import { SystemField } from "@calcom/features/bookings/lib/getBookingFields"; | ||
import type { bookingResponsesDbSchema } from "@calcom/features/bookings/lib/getBookingResponsesSchema"; | ||
import type { eventTypeBookingFields } from "@calcom/prisma/zod-utils"; | ||
import type { CalendarEvent } from "@calcom/types/Calendar"; | ||
|
||
export const getCalEventResponses = ({ | ||
bookingFields, | ||
responses, | ||
}: { | ||
// If the eventType has been deleted and a booking is Accepted later on, then bookingFields will be null and we can't know the label of fields. So, we should store the label as well in the DB | ||
// Also, it is no longer straightforward to identify if a field is system field or not | ||
bookingFields: z.infer<typeof eventTypeBookingFields> | null; | ||
responses: z.infer<typeof bookingResponsesDbSchema>; | ||
}) => { | ||
const calEventUserFieldsResponses = {} as NonNullable<CalendarEvent["userFieldsResponses"]>; | ||
const calEventResponses = {} as NonNullable<CalendarEvent["responses"]>; | ||
|
||
if (bookingFields) { | ||
bookingFields.forEach((field) => { | ||
const label = field.label || field.defaultLabel; | ||
if (!label) { | ||
throw new Error('Missing label for booking field "' + field.name + '"'); | ||
} | ||
if (field.editable === "user" || field.editable === "user-readonly") { | ||
calEventUserFieldsResponses[field.name] = { | ||
label, | ||
value: responses[field.name], | ||
}; | ||
} | ||
calEventResponses[field.name] = { | ||
label, | ||
value: responses[field.name], | ||
}; | ||
}); | ||
} else { | ||
// Alternative way to generate for a booking of whose eventType has been deleted | ||
for (const [name, value] of Object.entries(responses)) { | ||
const isSystemField = SystemField.safeParse(name); | ||
|
||
// Use name for Label because we don't have access to the label. This will not be needed once we start storing the label along with the response | ||
const label = name; | ||
|
||
if (!isSystemField.success) { | ||
calEventUserFieldsResponses[name] = { | ||
label, | ||
value, | ||
}; | ||
} | ||
|
||
calEventResponses[name] = { | ||
label, | ||
value, | ||
}; | ||
} | ||
} | ||
return { calEventUserFieldsResponses, calEventResponses }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
a8825ba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ui – ./apps/storybook
ui-git-main-cal.vercel.app
ui.cal.com
ui-cal.vercel.app
cal-com-storybook.vercel.app
timelessui.com
www.timelessui.com