fix: Booker atom name booking field (#18653)

* feat: split name booking field in v2

* fix: booker atom handle split name

* fix: after and before start dates bookings filter

* chore: bump platform libraries
This commit is contained in:
Lauris Skraucis authored and GitHub committed 2025-01-15 14:08:06 +05:30
1 parent 5ccf5e6be8
commit c21ba636d2
10 files changed
+6159 -262

No files matched your search

@@ -212,9 +212,20 @@ export const BookerPlatformWrapper = (
const { data: session } = useMe();
const hasSession = !!session;
const { name: defaultName, guests: defaultGuests, ...restFormValues } = props.defaultFormValues ?? {};
const prefillFormParamName = useMemo(() => {
if (defaultName) {
return defaultName;
}
if (restFormValues.firstName) {
return `${restFormValues.firstName} ${restFormValues.lastName}`;
}
return null;
}, [defaultName, restFormValues]);
const prefillFormParams = useMemo(() => {
return {
name: defaultName ?? null,
name: prefillFormParamName,
guests: defaultGuests ?? [],
};
}, [defaultName, defaultGuests]);
@@ -27,7 +27,8 @@ export class NameDefaultFieldInput_2024_06_14 {
@IsIn(inputBookingFieldTypes)
@DocsProperty({
example: "name",
description: "only allowed value for type is `name`",
description:
"only allowed value for type is `name`. Used for having 1 booking field for both first name and last name.",
})
type!: "name";
@@ -53,6 +54,52 @@ export class NameDefaultFieldInput_2024_06_14 {
disableOnPrefill?: boolean;
}
export class SplitNameDefaultFieldInput_2024_06_14 {
@IsIn(inputBookingFieldTypes)
@DocsProperty({
example: "splitName",
description:
"only allowed value for type is `splitName`. Used to have 2 booking fields - 1 for first name and 1 for last name.",
})
type!: "splitName";
@IsString()
@IsOptional()
@DocsProperty()
firstNameLabel?: string;
@IsString()
@IsOptional()
@DocsProperty()
firstNamePlaceholder?: string;
@IsString()
@IsOptional()
@DocsProperty()
lastNameLabel?: string;
@IsString()
@IsOptional()
@DocsProperty()
lastNamePlaceholder?: string;
@IsBoolean()
@IsOptional()
@DocsProperty({ description: "First name field is required but last name field is not by default." })
lastNameRequired?: boolean;
@IsBoolean()
@IsOptional()
@DocsPropertyOptional({
type: Boolean,
description:
"Disable this booking field if the URL contains query parameter with key equal to the slug and prefill it with the provided value.\
For example, if URL contains query parameter `&firstName=bob&lastName=jones`,\
the first name and last name fields will be prefilled with this value and disabled. In case of Booker atom need to pass firstName and lastName to defaultFormValues prop or pass name prop but as a string containing name and surname.",
})
disableOnPrefill?: boolean;
}
export class EmailDefaultFieldInput_2024_06_14 {
@IsIn(inputBookingFieldTypes)
@DocsProperty({
@@ -755,6 +802,7 @@ export class BooleanFieldInput_2024_06_14 {
type InputDefaultField_2024_06_14 =
| NameDefaultFieldInput_2024_06_14
| SplitNameDefaultFieldInput_2024_06_14
| EmailDefaultFieldInput_2024_06_14
| TitleDefaultFieldInput_2024_06_14
| NotesDefaultFieldInput_2024_06_14
@@ -779,6 +827,7 @@ export type InputBookingField_2024_06_14 =
class InputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInterface {
private classMap: { [key: string]: new () => InputBookingField_2024_06_14 } = {
name: NameDefaultFieldInput_2024_06_14,
splitName: SplitNameDefaultFieldInput_2024_06_14,
email: EmailDefaultFieldInput_2024_06_14,
title: TitleDefaultFieldInput_2024_06_14,
notes: NotesDefaultFieldInput_2024_06_14,
@@ -818,7 +867,7 @@ class InputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInterf
);
}
const fieldNeedsSlug = type !== "name" && type !== "email";
const fieldNeedsSlug = type !== "name" && type !== "splitName" && type !== "email";
if (fieldNeedsSlug && !slug) {
throw new BadRequestException(
`Each booking field except ones with type equal to name and email must have a 'slug' property.`
@@ -23,6 +23,7 @@ import {
NotesDefaultFieldInput_2024_06_14,
RescheduleReasonDefaultFieldInput_2024_06_14,
TitleDefaultFieldInput_2024_06_14,
SplitNameDefaultFieldInput_2024_06_14,
} from "../inputs";
export class NameDefaultFieldOutput_2024_06_14 extends NameDefaultFieldInput_2024_06_14 {
@@ -51,6 +52,28 @@ export class NameDefaultFieldOutput_2024_06_14 extends NameDefaultFieldInput_202
required!: boolean;
}
export class SplitNameDefaultFieldOutput_2024_06_14 extends SplitNameDefaultFieldInput_2024_06_14 {
@IsBoolean()
@DocsProperty({
description: "This property is always true because it's a default field",
example: true,
default: true,
})
isDefault = true;
@IsString()
@DocsProperty({
default: "splitName",
})
slug!: "splitName";
@IsString()
@DocsProperty({
default: "splitName",
})
type!: "splitName";
}
export class EmailDefaultFieldOutput_2024_06_14 extends EmailDefaultFieldInput_2024_06_14 {
@IsBoolean()
@DocsProperty({
@@ -550,6 +573,7 @@ export class OutputUnknownBookingField_2024_06_14 {
export type DefaultFieldOutput_2024_06_14 =
| NameDefaultFieldOutput_2024_06_14
| SplitNameDefaultFieldOutput_2024_06_14
| EmailDefaultFieldOutput_2024_06_14
| LocationDefaultFieldOutput_2024_06_14
| RescheduleReasonDefaultFieldOutput_2024_06_14
@@ -584,6 +608,7 @@ class OutputBookingFieldValidator_2024_06_14 implements ValidatorConstraintInter
private defaultOutputNameMap: { [key: string]: new () => DefaultFieldOutput_2024_06_14 } = {
name: NameDefaultFieldOutput_2024_06_14,
splitName: SplitNameDefaultFieldOutput_2024_06_14,
email: EmailDefaultFieldOutput_2024_06_14,
location: LocationDefaultFieldOutput_2024_06_14,
rescheduleReason: RescheduleReasonDefaultFieldOutput_2024_06_14,