Use the old booker redirect approach (#9589)

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
This commit is contained in:
Hariom Balhara
2023-06-17 20:42:15 +00:00
committed by GitHub
co-authored by Peer Richelsen
parent 856b090b4b
commit 448f57442b
2 changed files with 30 additions and 42 deletions
@@ -22,6 +22,7 @@ import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/
import getBookingResponsesSchema, {
getBookingResponsesPartialSchema,
} from "@calcom/features/bookings/lib/getBookingResponsesSchema";
import { bookingSuccessRedirect } from "@calcom/lib/bookingSuccessRedirect";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { HttpError } from "@calcom/lib/http-error";
import { Form, Button, Alert, EmptyScreen } from "@calcom/ui";
@@ -36,34 +37,11 @@ type BookEventFormProps = {
onCancel?: () => void;
};
const getSuccessPath = ({
uid,
email,
slug,
formerTime,
isRecurring,
}: {
uid: string;
email: string;
slug: string;
formerTime?: string;
isRecurring: boolean;
}) => ({
pathname: `/booking/${uid}`,
query: {
[isRecurring ? "allRemainingBookings" : "isSuccessBookingPage"]: true,
email: email,
eventTypeSlug: slug,
formerTime: formerTime,
},
});
export const BookEventForm = ({ onCancel }: BookEventFormProps) => {
const router = useRouter();
const { t, i18n } = useLocale();
const { timezone } = useTimePreferences();
const errorRef = useRef<HTMLDivElement>(null);
const rescheduleUid = useBookerStore((state) => state.rescheduleUid);
const rescheduleBooking = useBookerStore((state) => state.rescheduleBooking);
const eventSlug = useBookerStore((state) => state.eventSlug);
@@ -194,17 +172,20 @@ export const BookEventForm = ({ onCancel }: BookEventFormProps) => {
return;
}
return await router.push(
getSuccessPath({
uid,
email: bookingForm.getValues("responses.email"),
formerTime: rescheduleBooking?.startTime
? dayjs(rescheduleBooking?.startTime).toISOString()
: undefined,
slug: `${eventSlug}`,
isRecurring: false,
})
);
const query = {
isSuccessBookingPage: true,
email: bookingForm.getValues("responses.email"),
eventTypeSlug: eventSlug,
seatReferenceUid: "seatReferenceUid" in responseData ? responseData.seatReferenceUid : null,
formerTime: rescheduleBooking?.startTime ? dayjs(rescheduleBooking.startTime).toString() : undefined,
};
return bookingSuccessRedirect({
router,
successRedirectUrl: eventType?.successRedirectUrl || "",
query,
bookingUid: uid,
});
},
onError: () => {
errorRef && errorRef.current?.scrollIntoView({ behavior: "smooth" });
@@ -220,14 +201,20 @@ export const BookEventForm = ({ onCancel }: BookEventFormProps) => {
return;
}
return await router.push(
getSuccessPath({
uid,
email: bookingForm.getValues("responses.email"),
slug: `${eventSlug}`,
isRecurring: true,
})
);
const query = {
isSuccessBookingPage: true,
allRemainingBookings: true,
email: bookingForm.getValues("responses.email"),
eventTypeSlug: eventSlug,
formerTime: rescheduleBooking?.startTime ? dayjs(rescheduleBooking.startTime).toString() : undefined,
};
return bookingSuccessRedirect({
router,
successRedirectUrl: eventType?.successRedirectUrl || "",
query,
bookingUid: uid,
});
},
});
@@ -39,6 +39,7 @@ const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
seatsPerTimeSlot: true,
bookingFields: true,
team: true,
successRedirectUrl: true,
workflows: {
include: {
workflow: {