perf: Speed up User Type booking page (#20516)
* refactor [user]/[type] server logic * refactor useSlot * refactor * fix * fix OG images * fix
This commit is contained in:
1 parent
3b945ba439
commit
19a0f968ca
7 files changed
+53
-78
No files matched your search
@@ -5,7 +5,6 @@ import dayjs from "@calcom/dayjs";
|
||||
import { useBookerStore } from "@calcom/features/bookings/Booker/store";
|
||||
import { useSlotReservationId } from "@calcom/features/bookings/Booker/useSlotReservationId";
|
||||
import { isBookingDryRun } from "@calcom/features/bookings/Booker/utils/isBookingDryRun";
|
||||
import type { BookerEvent } from "@calcom/features/bookings/types";
|
||||
import {
|
||||
MINUTES_TO_BOOK,
|
||||
PUBLIC_QUERY_RESERVATION_INTERVAL_SECONDS,
|
||||
@@ -78,7 +77,7 @@ const useQuickAvailabilityChecks = ({
|
||||
|
||||
export type UseSlotsReturnType = ReturnType<typeof useSlots>;
|
||||
|
||||
export const useSlots = (event: { data?: Pick<BookerEvent, "id" | "length"> | null }) => {
|
||||
export const useSlots = (event: { id: number; length: number } | null) => {
|
||||
const selectedDuration = useBookerStore((state) => state.selectedDuration);
|
||||
const searchParams = useCompatSearchParams();
|
||||
const [selectedTimeslot, setSelectedTimeslot, tentativeSelectedTimeslots, setTentativeSelectedTimeslots] =
|
||||
@@ -107,13 +106,13 @@ export const useSlots = (event: { data?: Pick<BookerEvent, "id" | "length"> | nu
|
||||
});
|
||||
|
||||
const handleRemoveSlot = () => {
|
||||
if (event?.data) {
|
||||
if (event?.id && slotReservationId) {
|
||||
removeSelectedSlot.mutate({ uid: slotReservationId });
|
||||
}
|
||||
};
|
||||
|
||||
const eventTypeId = event.data?.id;
|
||||
const eventDuration = selectedDuration || event.data?.length || 0;
|
||||
const eventTypeId = event?.id;
|
||||
const eventDuration = selectedDuration || event?.length || 0;
|
||||
const allSelectedTimeslots = [...tentativeSelectedTimeslots, selectedTimeslot].filter(
|
||||
(slot): slot is string => slot !== null
|
||||
);
|
||||
@@ -153,7 +152,7 @@ export const useSlots = (event: { data?: Pick<BookerEvent, "id" | "length"> | nu
|
||||
clearInterval(interval);
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [event?.data?.id, timeSlotToBeBooked]);
|
||||
}, [event?.id, timeSlotToBeBooked]);
|
||||
|
||||
return {
|
||||
setSelectedTimeslot,
|
||||
|
||||
@@ -18,7 +18,7 @@ export type useScheduleForEventReturnType = ReturnType<typeof useScheduleForEven
|
||||
* Using this hook means you only need to use one hook, instead
|
||||
* of combining multiple conditional hooks.
|
||||
*/
|
||||
export const useEvent = (props?: { fromRedirectOfNonOrgLink?: boolean }) => {
|
||||
export const useEvent = (props?: { fromRedirectOfNonOrgLink?: boolean; disabled?: boolean }) => {
|
||||
const [username, eventSlug, isTeamEvent, org] = useBookerStore(
|
||||
(state) => [state.username, state.eventSlug, state.isTeamEvent, state.org],
|
||||
shallow
|
||||
@@ -34,7 +34,7 @@ export const useEvent = (props?: { fromRedirectOfNonOrgLink?: boolean }) => {
|
||||
},
|
||||
{
|
||||
refetchOnWindowFocus: false,
|
||||
enabled: Boolean(username) && Boolean(eventSlug),
|
||||
enabled: !props?.disabled && Boolean(username) && Boolean(eventSlug),
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -22,19 +22,32 @@ import { useBookerStore, useInitializeBookerStore } from "@calcom/features/booki
|
||||
import { useEvent, useScheduleForEvent } from "@calcom/features/bookings/Booker/utils/event";
|
||||
import { getLastBookingResponse } from "@calcom/features/bookings/Booker/utils/lastBookingResponse";
|
||||
import { useBrandColors } from "@calcom/features/bookings/Booker/utils/use-brand-colors";
|
||||
import type { getPublicEvent } from "@calcom/features/eventtypes/lib/getPublicEvent";
|
||||
import { DEFAULT_LIGHT_BRAND_COLOR, DEFAULT_DARK_BRAND_COLOR, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { useRouterQuery } from "@calcom/lib/hooks/useRouterQuery";
|
||||
import { BookerLayouts } from "@calcom/prisma/zod-utils";
|
||||
|
||||
type BookerWebWrapperAtomProps = BookerProps;
|
||||
type BookerWebWrapperAtomProps = BookerProps & {
|
||||
eventData?: NonNullable<Awaited<ReturnType<typeof getPublicEvent>>>;
|
||||
};
|
||||
|
||||
export const BookerWebWrapper = (props: BookerWebWrapperAtomProps) => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
const event = useEvent({
|
||||
const clientFetchedEvent = useEvent({
|
||||
disabled: !!props.eventData,
|
||||
fromRedirectOfNonOrgLink: props.entity.fromRedirectOfNonOrgLink,
|
||||
});
|
||||
const event = props.eventData
|
||||
? {
|
||||
data: props.eventData,
|
||||
isSuccess: true,
|
||||
isError: false,
|
||||
isPending: false,
|
||||
}
|
||||
: clientFetchedEvent;
|
||||
|
||||
const bookerLayout = useBookerLayout(event.data);
|
||||
|
||||
const selectedDate = searchParams?.get("date");
|
||||
@@ -110,7 +123,7 @@ export const BookerWebWrapper = (props: BookerWebWrapperAtomProps) => {
|
||||
requiresBookerEmailVerification: event?.data?.requiresBookerEmailVerification,
|
||||
onVerifyEmail: bookerForm.beforeVerifyEmail,
|
||||
});
|
||||
const slots = useSlots(event);
|
||||
const slots = useSlots(event?.data ? { id: event.data.id, length: event.data.length } : null);
|
||||
|
||||
const isEmbed = useIsEmbed();
|
||||
|
||||
|
||||
Reference in new issue
Block a user