fix: Prefill issue when name isn't present and add unit tests (#11418)
* Fix yarn.lock * Add tests for getBookingResponsesSchema * Fix prefill failing if name isnt provided * More tests and another fix
This commit is contained in:
1 parent
a0642598ab
commit
4acfb4b28c
4 files changed
+1048
-12
No files matched your search
@@ -22,8 +22,6 @@ import { isSupportedTimeZone } from "@calcom/lib/date-fns";
|
||||
import { slugify } from "@calcom/lib/slugify";
|
||||
import { EventTypeCustomInputType } from "@calcom/prisma/enums";
|
||||
|
||||
export const nonEmptyString = () => z.string().refine((value: string) => value.trim().length > 0);
|
||||
|
||||
// Let's not import 118kb just to get an enum
|
||||
export enum Frequency {
|
||||
YEARLY = 0,
|
||||
@@ -115,14 +113,15 @@ export type BookingFieldType = FormBuilderFieldType;
|
||||
|
||||
// Validation of user added bookingFields' responses happen using `getBookingResponsesSchema` which requires `eventType`.
|
||||
// So it is a dynamic validation and thus entire validation can't exist here
|
||||
// Note that this validation runs to validate prefill params as well, so it should consider that partial values can be there. e.g. `name` might be empty string
|
||||
export const bookingResponses = z
|
||||
.object({
|
||||
email: z.string(),
|
||||
//TODO: Why don't we move name out of bookingResponses and let it be handled like user fields?
|
||||
name: z.union([
|
||||
nonEmptyString(),
|
||||
z.string(),
|
||||
z.object({
|
||||
firstName: nonEmptyString(),
|
||||
firstName: z.string(),
|
||||
lastName: z.string().optional(),
|
||||
}),
|
||||
]),
|
||||
|
||||
Reference in new issue
Block a user