Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions packages/features/bookings/Booker/Booker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { RedirectToInstantMeetingModal } from "./components/RedirectToInstantMee
import { BookerSection } from "./components/Section";
import { NotFound } from "./components/Unavailable";
import { useIsQuickAvailabilityCheckFeatureEnabled } from "./components/hooks/useIsQuickAvailabilityCheckFeatureEnabled";
import { fadeInLeft, getBookerSizeClassNames, useBookerResizeAnimation } from "./config";
import { extraDaysConfig, fadeInLeft, getBookerSizeClassNames, useBookerResizeAnimation } from "./config";
import framerFeatures from "./framer-features";
import type { BookerProps, WrappedBookerProps } from "./types";
import { isBookingDryRun } from "./utils/isBookingDryRun";
Expand Down Expand Up @@ -103,6 +103,7 @@ const BookerComponent = ({
hideEventTypeDetails,
isEmbed,
bookerLayouts,
isTablet,
} = bookerLayout;

const [seatedEventData, setSeatedEventData] = useBookerStoreContext(
Expand All @@ -128,9 +129,53 @@ const BookerComponent = ({
: 0;
// Taking one more available slot(extraDays + 1) to calculate the no of days in between, that next and prev button need to shift.
const availableSlots = nonEmptyScheduleDays.slice(0, extraDays + 1);
if (nonEmptyScheduleDays.length !== 0)
columnViewExtraDays.current =
Math.abs(dayjs(selectedDate).diff(availableSlots[availableSlots.length - 2], "day")) + addonDays;

const columnViewExtraDaysConfig = isTablet
? extraDaysConfig[BookerLayouts.COLUMN_VIEW].tablet
: extraDaysConfig[BookerLayouts.COLUMN_VIEW].desktop;

const relevantDates = nonEmptyScheduleDays.slice(0, columnViewExtraDaysConfig + 1).join(",");

const calculatedColumnViewExtraDays = useMemo(() => {
if (layout !== BookerLayouts.COLUMN_VIEW) {
return columnViewExtraDays.current;
}

if (nonEmptyScheduleDays.length === 0) {
return columnViewExtraDaysConfig;
}

const columnAddonDays =
nonEmptyScheduleDays.length < columnViewExtraDaysConfig
? (columnViewExtraDaysConfig - nonEmptyScheduleDays.length + 1) * totalWeekDays
: nonEmptyScheduleDays.length === columnViewExtraDaysConfig
? totalWeekDays
: 0;

const columnAvailableSlots = nonEmptyScheduleDays.slice(0, columnViewExtraDaysConfig + 1);

if (columnAvailableSlots.length < 2) {
return columnViewExtraDaysConfig;
}

const calculated =
Math.abs(dayjs(selectedDate).diff(columnAvailableSlots[columnAvailableSlots.length - 2], "day")) +
columnAddonDays;

return calculated;
}, [
layout,
selectedDate,
relevantDates,
nonEmptyScheduleDays.length,
isTablet,
columnViewExtraDays,
columnViewExtraDaysConfig,
]);

if (layout === BookerLayouts.COLUMN_VIEW) {
columnViewExtraDays.current = calculatedColumnViewExtraDays;
}

const nextSlots =
Math.abs(dayjs(selectedDate).diff(availableSlots[availableSlots.length - 1], "day")) + addonDays;
Expand Down
6 changes: 6 additions & 0 deletions packages/features/bookings/Booker/__mocks__/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ vi.mock("../config", () => ({
useBookerResizeAnimation: () => ({ current: document.createElement("div") }),
getBookerSizeClassNames: () => [],
fadeInLeft: {},
extraDaysConfig: {
mobile: {desktop: 0, tablet: 0},
month_view: {desktop: 0, tablet: 0},
week_view: {desktop: 7, tablet: 4},
column_view: {desktop: 6, tablet: 2},
}
}));
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const defaultProps = {
extraDays: 7,
columnViewExtraDays: { current: 7 },
isMobile: false,
isTablet: false,
layout: "MONTH_VIEW",
hideEventTypeDetails: false,
isEmbed: false,
Expand Down
Loading