Skip to content

Commit 010ee0d

Browse files
add-tests- usePrefetch (calcom#23918)
1 parent f0a7d69 commit 010ee0d

8 files changed

Lines changed: 737 additions & 114 deletions

File tree

packages/features/bookings/Booker/components/hooks/usePrefetch.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

packages/features/bookings/Booker/utils/event.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,40 @@ export const useEvent = (props?: { fromRedirectOfNonOrgLink?: boolean; disabled?
5959
* this way the multi day view will show data of both months.
6060
*/
6161
export const useScheduleForEvent = ({
62-
prefetchNextMonth,
6362
username,
6463
eventSlug,
6564
eventId,
6665
month,
6766
duration,
68-
monthCount,
6967
dayCount,
7068
selectedDate,
7169
orgSlug,
7270
teamMemberEmail,
7371
isTeamEvent,
7472
useApiV2 = true,
73+
bookerLayout,
7574
}: {
76-
prefetchNextMonth?: boolean;
7775
username?: string | null;
7876
eventSlug?: string | null;
7977
eventId?: number | null;
8078
month?: string | null;
8179
duration?: number | null;
82-
monthCount?: number;
8380
dayCount?: number | null;
8481
selectedDate?: string | null;
8582
orgSlug?: string;
8683
teamMemberEmail?: string | null;
8784
fromRedirectOfNonOrgLink?: boolean;
8885
isTeamEvent?: boolean;
8986
useApiV2?: boolean;
90-
} = {}) => {
87+
/**
88+
* Required when prefetching is needed
89+
*/
90+
bookerLayout?: {
91+
layout: string;
92+
extraDays: number;
93+
columnViewExtraDays: { current: number };
94+
};
95+
}) => {
9196
const { timezone } = useBookerTime();
9297
const [usernameFromStore, eventSlugFromStore, monthFromStore, durationFromStore] = useBookerStoreContext(
9398
(state) => [state.username, state.eventSlug, state.month, state.selectedDuration],
@@ -103,8 +108,6 @@ export const useScheduleForEvent = ({
103108
eventId,
104109
timezone,
105110
selectedDate,
106-
prefetchNextMonth,
107-
monthCount,
108111
dayCount,
109112
rescheduleUid,
110113
month: monthFromStore ?? month,
@@ -113,6 +116,7 @@ export const useScheduleForEvent = ({
113116
orgSlug,
114117
teamMemberEmail,
115118
useApiV2: useApiV2,
119+
bookerLayout,
116120
});
117121

118122
return {

packages/features/schedules/lib/use-schedule/useSchedule.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { updateEmbedBookerState } from "@calcom/embed-core/src/embed-iframe";
44
import { sdkActionManager } from "@calcom/embed-core/src/sdk-event";
55
import { useBookerStore } from "@calcom/features/bookings/Booker/store";
66
import { isBookingDryRun } from "@calcom/features/bookings/Booker/utils/isBookingDryRun";
7+
import { getUsernameList } from "@calcom/features/eventtypes/lib/defaultEvents";
78
import { useTimesForSchedule } from "@calcom/features/schedules/lib/use-schedule/useTimesForSchedule";
89
import { getRoutedTeamMemberIdsFromSearchParams } from "@calcom/lib/bookings/getRoutedTeamMemberIdsFromSearchParams";
910
import { PUBLIC_QUERY_AVAILABLE_SLOTS_INTERVAL_SECONDS } from "@calcom/lib/constants";
10-
import { getUsernameList } from "@calcom/features/eventtypes/lib/defaultEvents";
1111
import { trpc } from "@calcom/trpc/react";
1212

1313
import { useApiV2AvailableSlots } from "./useApiV2AvailableSlots";
@@ -19,16 +19,22 @@ export type UseScheduleWithCacheArgs = {
1919
month?: string | null;
2020
timezone?: string | null;
2121
selectedDate?: string | null;
22-
prefetchNextMonth?: boolean;
2322
duration?: number | null;
24-
monthCount?: number | null;
2523
dayCount?: number | null;
2624
rescheduleUid?: string | null;
2725
isTeamEvent?: boolean;
2826
orgSlug?: string;
2927
teamMemberEmail?: string | null;
3028
useApiV2?: boolean;
3129
enabled?: boolean;
30+
/***
31+
* Required when prefetching is needed
32+
*/
33+
bookerLayout?: {
34+
layout: string;
35+
extraDays: number;
36+
columnViewExtraDays: { current: number };
37+
};
3238
};
3339

3440
const getAvailabilityLoadedEventPayload = ({
@@ -51,25 +57,23 @@ export const useSchedule = ({
5157
eventSlug,
5258
eventId,
5359
selectedDate,
54-
prefetchNextMonth,
5560
duration,
56-
monthCount,
5761
dayCount,
5862
rescheduleUid,
5963
isTeamEvent,
6064
orgSlug,
6165
teamMemberEmail,
6266
useApiV2 = false,
6367
enabled: enabledProp = true,
68+
bookerLayout,
6469
}: UseScheduleWithCacheArgs) => {
6570
const bookerState = useBookerStore((state) => state.state);
6671

6772
const [startTime, endTime] = useTimesForSchedule({
6873
month,
69-
monthCount,
7074
dayCount,
71-
prefetchNextMonth,
7275
selectedDate,
76+
bookerLayout,
7377
});
7478
const searchParams = useSearchParams();
7579
const routedTeamMemberIds = searchParams
@@ -99,7 +103,9 @@ export const useSchedule = ({
99103
startTime,
100104
// if `prefetchNextMonth` is true, two months are fetched at once.
101105
endTime,
102-
timeZone: timezone!,
106+
// We use a placeholder value that is there to keep TS happy, but still invalid to tell us that it shouldn't actually be passed in request(and wouldn't because enabled is false if timezone is nullish)
107+
// TODO: Better approach here is to use `skipToken` from react-query which requires an upgrade of react-query
108+
timeZone: timezone ?? "PLACEHOLDER_TIMEZONE",
103109
duration: duration ? `${duration}` : undefined,
104110
rescheduleUid,
105111
orgSlug,

0 commit comments

Comments
 (0)