Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: removed the confirm step in creating bookings #18380

Closed
42 changes: 35 additions & 7 deletions packages/features/bookings/Booker/Booker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,43 @@ const BookerComponent = ({
}
};

const checkRequiredFieldsFilled = (
fields: NonNullable<RouterOutputs["viewer"]["public"]["event"]>["bookingFields"],
values: any
): boolean => {
// We're skipping title field because it may not exist in form values
const requiredFields = fields.filter((field) => field.required && field.name !== "title");
return requiredFields.every((field) => {
const value = values[field.name];
return value !== undefined && value !== null && value !== "";
});
};

useEffect(() => {
if (event.isPending) return setBookerState("loading");
if (!selectedDate) return setBookerState("selecting_date");
if (!selectedTimeslot) return setBookerState("selecting_time");
if (event.isPending) {
setBookerState("loading");
return;
}
if (!selectedDate) {
setBookerState("selecting_date");
return;
}
if (!selectedTimeslot) {
setBookerState("selecting_time");
return;
}

return setBookerState("booking");
}, [event, selectedDate, selectedTimeslot, setBookerState]);
}, [event, selectedDate, selectedTimeslot, setBookerState, handleBookEvent, bookerState]);

useEffect(() => {
if (event.data && bookingForm && event.data.bookingFields && bookingForm.getValues().responses) {
// Problem here is that this bookingForm is updated everytime you type
// The feature is that it should only run once when the state is in booking and the URL params fulfil the requirements
if (checkRequiredFieldsFilled(event.data.bookingFields, bookingForm.getValues().responses))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to check for optional fields as well. So only if ALL fields (required & optional) are prefilled we want to skip the form

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Carina here, empty values for optional fields should probably be explicitly defined

handleBookEvent();
}
}, [bookingForm, event.data, handleBookEvent]);

const slot = getQueryParam("slot");
useEffect(() => {
Expand Down Expand Up @@ -270,9 +301,7 @@ const BookerComponent = ({
return (
<>
{event.data && !isPlatform ? <BookingPageTagManager eventType={event.data} /> : <></>}

{isBookingDryRun(searchParams) && <DryRunMessage isEmbed={isEmbed} />}

<div
className={classNames(
// In a popup embed, if someone clicks outside the main(having main class or main tag), it closes the embed
Expand Down Expand Up @@ -480,7 +509,6 @@ const BookerComponent = ({
</m.span>
)}
</div>

<BookFormAsModal
onCancel={() => setSelectedTimeslot(null)}
visible={bookerState === "booking" && shouldShowFormInDialog}>
Expand Down
Loading