Skip to content

Commit 445b307

Browse files
authored
fix: week view and column view slots not fetching at end of month bug (calcom#24374)
* fix: dont pick date value from url, use selectedDate value from booker store instead * fix: replace month count logic with usePrefectch hook * intialise booker layout as week view
1 parent d2d86a4 commit 445b307

2 files changed

Lines changed: 9 additions & 18 deletions

File tree

packages/platform/atoms/booker/BookerWebWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const BookerPlatformWrapperComponent = (props: BookerWebWrapperAtomProps) => {
5555
: clientFetchedEvent;
5656

5757
const bookerLayout = useBookerLayout(event.data?.profile?.bookerLayouts);
58-
const selectedDate = searchParams?.get("date");
58+
const selectedDate = useBookerStoreContext((state) => state.selectedDate);
5959
const isRedirect = searchParams?.get("redirected") === "true" || false;
6060
const fromUserNameRedirected = searchParams?.get("username") || "";
6161
const rescheduleUid =

packages/platform/atoms/calendar-view/wrappers/CalendarViewPlatformWrapper.tsx

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import {
1111
import { Header } from "@calcom/features/bookings/Booker/components/Header";
1212
import { BookerSection } from "@calcom/features/bookings/Booker/components/Section";
1313
import { useBookerLayout } from "@calcom/features/bookings/Booker/components/hooks/useBookerLayout";
14+
import { usePrefetch } from "@calcom/features/bookings/Booker/components/hooks/usePrefetch";
1415
import { useTimePreferences } from "@calcom/features/bookings/lib";
1516
import { LargeCalendar } from "@calcom/features/calendar-view/LargeCalendar";
1617
import { getUsernameList } from "@calcom/features/eventtypes/lib/defaultEvents";
1718
import { useTimesForSchedule } from "@calcom/features/schedules/lib/use-schedule/useTimesForSchedule";
1819
import { getRoutedTeamMemberIdsFromSearchParams } from "@calcom/lib/bookings/getRoutedTeamMemberIdsFromSearchParams";
19-
import { BookerLayouts } from "@calcom/prisma/zod-utils";
2020

2121
import { formatUsername } from "../../booker/BookerPlatformWrapper";
2222
import type {
@@ -40,7 +40,6 @@ const CalendarViewPlatformWrapperComponent = (
4040
teamMemberEmail,
4141
crmAppSlug,
4242
crmOwnerRecordType,
43-
view = "MONTH_VIEW",
4443
} = props;
4544

4645
const teamId: number | undefined = props.isTeamEvent ? props.teamId : undefined;
@@ -73,22 +72,15 @@ const CalendarViewPlatformWrapperComponent = (
7372
);
7473
const selectedDate = useBookerStoreContext((state) => state.selectedDate);
7574
const date = dayjs(selectedDate).format("YYYY-MM-DD");
76-
const monthCount =
77-
((bookerLayout.layout !== BookerLayouts.WEEK_VIEW && bookerState === "selecting_time") ||
78-
bookerLayout.layout === BookerLayouts.COLUMN_VIEW) &&
79-
dayjs(date).add(1, "month").month() !==
80-
dayjs(date).add(bookerLayout.columnViewExtraDays.current, "day").month()
81-
? 2
82-
: undefined;
8375
const month = useBookerStoreContext((state) => state.month);
8476
const [dayCount] = useBookerStoreContext((state) => [state.dayCount, state.setDayCount], shallow);
8577

86-
const prefetchNextMonth =
87-
(bookerLayout.layout === BookerLayouts.WEEK_VIEW &&
88-
!!bookerLayout.extraDays &&
89-
dayjs(date).month() !== dayjs(date).add(bookerLayout.extraDays, "day").month()) ||
90-
(bookerLayout.layout === BookerLayouts.COLUMN_VIEW &&
91-
dayjs(date).month() !== dayjs(date).add(bookerLayout.columnViewExtraDays.current, "day").month());
78+
const { prefetchNextMonth, monthCount } = usePrefetch({
79+
date,
80+
month,
81+
bookerLayout,
82+
bookerState,
83+
});
9284

9385
const [startTime, endTime] = useTimesForSchedule({
9486
month,
@@ -136,7 +128,6 @@ const CalendarViewPlatformWrapperComponent = (
136128
}, [props.routingFormSearchParams]);
137129
const bookingData = useBookerStoreContext((state) => state.bookingData);
138130
const setBookingData = useBookerStoreContext((state) => state.setBookingData);
139-
const layout = BookerLayouts[view];
140131

141132
useGetBookingForReschedule({
142133
uid: props.rescheduleUid ?? props.bookingUid ?? "",
@@ -154,7 +145,7 @@ const CalendarViewPlatformWrapperComponent = (
154145
eventId: event?.data?.id,
155146
rescheduleUid: props.rescheduleUid ?? null,
156147
bookingUid: props.bookingUid ?? null,
157-
layout: layout,
148+
layout: "week_view",
158149
org: props.entity?.orgSlug,
159150
username,
160151
bookingData,

0 commit comments

Comments
 (0)