fix: scroll issues in Embed (#26583)
* chore: add new view for two step slot selection for embed * fix: make sure two step slot selection is false by default * chore: update embed playground to showcase two step slot selection * chore: add tests * chore: update embed snippet generator code to include two step slot selection * chore: update docs * fix: back button styling * chore: implement feedback from cubic * fix: add missing isEnableTwoStepSlotSelectionVisible properties to test mock store Co-Authored-By: unknown <> * chore: implement PR feedback * chore: update slot selection modal * chore: add prop to hide available times header * fix: scope two-step slot selection visibility to mobile only Restores the isMobile check in the timeslot visibility guard to ensure desktop embeds continue to show the booking UI when two-step slot selection is enabled. The feature should only hide the timeslot list on mobile devices. Addresses Cubic AI review feedback (confidence 9/10). Co-Authored-By: unknown <> * fixup: use translations for loading instead of actual word * fix: type check * fix: add window.matchMedia mock for jsdom test environment Co-Authored-By: [email protected] <[email protected]> * fix: add window.matchMedia mock to packages/testing/src/setupVitest.ts Co-Authored-By: [email protected] <[email protected]> * fix: unit tests failing * add a width style to the two-step slot selection embed container. * refactor: rename enableTwoStepSlotSelection to useSlotsViewOnSmallScreen - Rename external-facing embed config option from enableTwoStepSlotSelection to useSlotsViewOnSmallScreen - Update URL parameter parsing in embed-iframe.ts - Update type definitions in types.ts and index.d.ts - Update internal variable names to slotsViewOnSmallScreen for consistency - Update documentation, playground examples, and tests Co-Authored-By: [email protected] <[email protected]> * Add config to prefill all booking fields so that slot has confirm button along with it * chore: implement PR feedback * fix: move twoStepSlotSelection embed outside misc-embeds div to fix e2e test The e2e test was failing because the misc-embeds div content was intercepting pointer events on mobile viewport. This follows the same pattern used for skeletonDemo - the embed is now outside misc-embeds and the div is hidden when testing this namespace. Co-Authored-By: [email protected] <[email protected]> * fix: prevent pointer event interception in twoStepSlotSelection embed Hide heading and note elements and set pointer-events: none on container elements while keeping pointer-events: auto on the iframe container. This prevents the container from intercepting clicks on the iframe during mobile viewport e2e tests. Co-Authored-By: [email protected] <[email protected]> * fix: hide all non-essential content for twoStepSlotSelection e2e test Co-Authored-By: [email protected] <[email protected]> * fix: disable pointer-events on body for twoStepSlotSelection e2e test Co-Authored-By: [email protected] <[email protected]> * fix: remove pointer-events: auto on container to let clicks pass through to iframe Co-Authored-By: [email protected] <[email protected]> * fix: explicitly set pointer-events: none on container and inline-embed-container Co-Authored-By: [email protected] <[email protected]> * fix: also set pointer-events: none on html element to prevent interception Co-Authored-By: [email protected] <[email protected]> * fix: make .place div fill viewport for twoStepSlotSelection e2e test Co-Authored-By: [email protected] <[email protected]> * fix: failing embed tests * fixup * fixup fixup * fix: failing tests * fix: update checks for verifying prefilled date --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
29 files changed
+1420
-260
No files matched your search
@@ -1,7 +1,10 @@
|
||||
import { useCallback, useMemo, useRef } from "react";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { AvailableTimes, AvailableTimesSkeleton } from "@calcom/web/modules/bookings/components/AvailableTimes";
|
||||
import {
|
||||
AvailableTimes,
|
||||
AvailableTimesSkeleton,
|
||||
} from "@calcom/web/modules/bookings/components/AvailableTimes";
|
||||
import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider";
|
||||
import type { IUseBookingLoadingStates } from "@calcom/features/bookings/Booker/components/hooks/useBookings";
|
||||
import type { BookerEvent } from "@calcom/features/bookings/types";
|
||||
@@ -25,7 +28,10 @@ type AvailableTimeSlotsProps = {
|
||||
seatsPerTimeSlot?: number | null;
|
||||
showAvailableSeatsCount?: boolean | null;
|
||||
event: {
|
||||
data?: Pick<BookerEvent, "length" | "bookingFields" | "price" | "currency" | "metadata"> | null;
|
||||
data?: Pick<
|
||||
BookerEvent,
|
||||
"length" | "bookingFields" | "price" | "currency" | "metadata"
|
||||
> | null;
|
||||
};
|
||||
customClassNames?: {
|
||||
availableTimeSlotsContainer?: string;
|
||||
@@ -50,6 +56,7 @@ type AvailableTimeSlotsProps = {
|
||||
unavailableTimeSlots: string[];
|
||||
confirmButtonDisabled?: boolean;
|
||||
onAvailableTimeSlotSelect: (time: string) => void;
|
||||
hideAvailableTimesHeader?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -74,19 +81,23 @@ export const AvailableTimeSlots = ({
|
||||
confirmButtonDisabled,
|
||||
confirmStepClassNames,
|
||||
onAvailableTimeSlotSelect,
|
||||
hideAvailableTimesHeader = false,
|
||||
...props
|
||||
}: AvailableTimeSlotsProps) => {
|
||||
const selectedDate = useBookerStoreContext((state) => state.selectedDate);
|
||||
|
||||
const setSeatedEventData = useBookerStoreContext((state) => state.setSeatedEventData);
|
||||
const setSeatedEventData = useBookerStoreContext(
|
||||
(state) => state.setSeatedEventData
|
||||
);
|
||||
const date = selectedDate || dayjs().format("YYYY-MM-DD");
|
||||
const [layout] = useBookerStoreContext((state) => [state.layout]);
|
||||
const isColumnView = layout === BookerLayouts.COLUMN_VIEW;
|
||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||
const { setTentativeSelectedTimeslots, tentativeSelectedTimeslots } = useBookerStoreContext((state) => ({
|
||||
setTentativeSelectedTimeslots: state.setTentativeSelectedTimeslots,
|
||||
tentativeSelectedTimeslots: state.tentativeSelectedTimeslots,
|
||||
}));
|
||||
const { setTentativeSelectedTimeslots, tentativeSelectedTimeslots } =
|
||||
useBookerStoreContext((state) => ({
|
||||
setTentativeSelectedTimeslots: state.setTentativeSelectedTimeslots,
|
||||
tentativeSelectedTimeslots: state.tentativeSelectedTimeslots,
|
||||
}));
|
||||
|
||||
const onTentativeTimeSelect = ({
|
||||
time,
|
||||
@@ -124,13 +135,22 @@ export const AvailableTimeSlots = ({
|
||||
return [];
|
||||
}, [date, extraDays, nonEmptyScheduleDaysFromSelectedDate]);
|
||||
|
||||
const { slotsPerDay, toggleConfirmButton } = useSlotsForAvailableDates(dates, scheduleData?.slots);
|
||||
const { slotsPerDay, toggleConfirmButton } = useSlotsForAvailableDates(
|
||||
dates,
|
||||
scheduleData?.slots
|
||||
);
|
||||
|
||||
const overlayCalendarToggled =
|
||||
getQueryParam("overlayCalendar") === "true" || localStorage.getItem("overlayCalendarSwitchDefault");
|
||||
getQueryParam("overlayCalendar") === "true" ||
|
||||
localStorage.getItem("overlayCalendarSwitchDefault");
|
||||
|
||||
const onTimeSelect = useCallback(
|
||||
(time: string, attendees: number, seatsPerTimeSlot?: number | null, bookingUid?: string) => {
|
||||
(
|
||||
time: string,
|
||||
attendees: number,
|
||||
seatsPerTimeSlot?: number | null,
|
||||
bookingUid?: string
|
||||
) => {
|
||||
// Temporarily allow disabling it, till we are sure that it doesn't cause any significant load on the system
|
||||
if (PUBLIC_INVALIDATE_AVAILABLE_SLOTS_ON_BOOKING_FORM) {
|
||||
// Ensures that user has latest available slots when they are about to confirm the booking by filling up the details
|
||||
@@ -181,12 +201,24 @@ export const AvailableTimeSlots = ({
|
||||
);
|
||||
}
|
||||
},
|
||||
[overlayCalendarToggled, onTimeSelect, seatsPerTimeSlot, skipConfirmStep, toggleConfirmButton]
|
||||
[
|
||||
overlayCalendarToggled,
|
||||
onTimeSelect,
|
||||
seatsPerTimeSlot,
|
||||
skipConfirmStep,
|
||||
toggleConfirmButton,
|
||||
]
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={classNames(`flex`, `${customClassNames?.availableTimeSlotsContainer}`)}>
|
||||
<div
|
||||
className={classNames(
|
||||
`flex`,
|
||||
hideAvailableTimesHeader && "hidden",
|
||||
`${customClassNames?.availableTimeSlotsContainer}`
|
||||
)}
|
||||
>
|
||||
{isLoading ? (
|
||||
<div className="mb-3 h-8" />
|
||||
) : (
|
||||
@@ -197,15 +229,19 @@ export const AvailableTimeSlots = ({
|
||||
return (
|
||||
<AvailableTimesHeader
|
||||
customClassNames={{
|
||||
availableTimeSlotsHeaderContainer: customClassNames?.availableTimeSlotsHeaderContainer,
|
||||
availableTimeSlotsTitle: customClassNames?.availableTimeSlotsTitle,
|
||||
availableTimeSlotsTimeFormatToggle: customClassNames?.availableTimeSlotsTimeFormatToggle,
|
||||
availableTimeSlotsHeaderContainer:
|
||||
customClassNames?.availableTimeSlotsHeaderContainer,
|
||||
availableTimeSlotsTitle:
|
||||
customClassNames?.availableTimeSlotsTitle,
|
||||
availableTimeSlotsTimeFormatToggle:
|
||||
customClassNames?.availableTimeSlotsTimeFormatToggle,
|
||||
}}
|
||||
key={slots.date}
|
||||
date={dayjs(slots.date)}
|
||||
showTimeFormatToggle={!isColumnView && !isOOODay}
|
||||
availableMonth={
|
||||
dayjs(selectedDate).format("MM") !== dayjs(slots.date).format("MM")
|
||||
dayjs(selectedDate).format("MM") !==
|
||||
dayjs(slots.date).format("MM")
|
||||
? dayjs(slots.date).format("MMM")
|
||||
: undefined
|
||||
}
|
||||
@@ -221,13 +257,19 @@ export const AvailableTimeSlots = ({
|
||||
limitHeight && "no-scrollbar grow overflow-auto md:h-[400px]",
|
||||
!limitHeight && "flex h-full w-full flex-row gap-4",
|
||||
`${customClassNames?.availableTimeSlotsContainer}`
|
||||
)}>
|
||||
)}
|
||||
>
|
||||
{isLoading && // Shows exact amount of days as skeleton.
|
||||
Array.from({ length: 1 + (extraDays ?? 0) }).map((_, i) => <AvailableTimesSkeleton key={i} />)}
|
||||
Array.from({ length: 1 + (extraDays ?? 0) }).map((_, i) => (
|
||||
<AvailableTimesSkeleton key={i} />
|
||||
))}
|
||||
{!isLoading &&
|
||||
slotsPerDay.length > 0 &&
|
||||
slotsPerDay.map((slots) => (
|
||||
<div key={slots.date} className="no-scrollbar overflow-x-hidden! h-full w-full overflow-y-auto">
|
||||
<div
|
||||
key={slots.date}
|
||||
className="no-scrollbar overflow-x-hidden! h-full w-full overflow-y-auto"
|
||||
>
|
||||
<AvailableTimes
|
||||
className={customClassNames?.availableTimeSlotsContainer}
|
||||
customClassNames={customClassNames?.availableTimes}
|
||||
|
||||
@@ -13,12 +13,30 @@ import "@calcom/lib/__mocks__/logger";
|
||||
import React from "react";
|
||||
import { vi } from "vitest";
|
||||
|
||||
vi.mock("next/navigation", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("next/navigation")>();
|
||||
return {
|
||||
...actual,
|
||||
useRouter: () => ({
|
||||
push: vi.fn(),
|
||||
replace: vi.fn(),
|
||||
back: vi.fn(),
|
||||
forward: vi.fn(),
|
||||
refresh: vi.fn(),
|
||||
prefetch: vi.fn(),
|
||||
}),
|
||||
usePathname: () => "/test-path",
|
||||
useSearchParams: () => new URLSearchParams(),
|
||||
useParams: () => ({}),
|
||||
};
|
||||
});
|
||||
|
||||
import "@calcom/dayjs/__mocks__";
|
||||
import "@calcom/features/auth/Turnstile";
|
||||
|
||||
import { Booker } from "./Booker";
|
||||
import { render, screen } from "@calcom/features/bookings/Booker/__tests__/test-utils";
|
||||
import type { BookerProps, WrappedBookerProps } from "@calcom/features/bookings/Booker/types";
|
||||
import { Booker } from "./Booker";
|
||||
|
||||
vi.mock("framer-motion", async (importOriginal) => {
|
||||
const actual = (await importOriginal()) as any;
|
||||
@@ -175,9 +193,12 @@ describe("Booker", () => {
|
||||
});
|
||||
|
||||
it("should render null when in loading state", () => {
|
||||
const { container } = render(<Booker {...defaultProps as unknown as BookerProps & WrappedBookerProps} />, {
|
||||
mockStore: { state: "loading" },
|
||||
});
|
||||
const { container } = render(
|
||||
<Booker {...(defaultProps as unknown as BookerProps & WrappedBookerProps)} />,
|
||||
{
|
||||
mockStore: { state: "loading" },
|
||||
}
|
||||
);
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
@@ -194,7 +215,7 @@ describe("Booker", () => {
|
||||
},
|
||||
};
|
||||
|
||||
render(<Booker {...propsWithDryRun as unknown as BookerProps & WrappedBookerProps} />, {
|
||||
render(<Booker {...(propsWithDryRun as unknown as BookerProps & WrappedBookerProps)} />, {
|
||||
mockStore: {
|
||||
state: "selecting_time",
|
||||
selectedDate: "2024-01-01",
|
||||
@@ -218,7 +239,7 @@ describe("Booker", () => {
|
||||
},
|
||||
};
|
||||
|
||||
render(<Booker {...propsWithInvalidate as unknown as BookerProps & WrappedBookerProps} />, {
|
||||
render(<Booker {...(propsWithInvalidate as unknown as BookerProps & WrappedBookerProps)} />, {
|
||||
mockStore: { state: "booking" },
|
||||
});
|
||||
screen.logTestingPlaygroundURL();
|
||||
@@ -240,11 +261,11 @@ describe("Booker", () => {
|
||||
},
|
||||
};
|
||||
|
||||
render(<Booker {...propsWithQuickChecks as unknown as BookerProps & WrappedBookerProps} />, {
|
||||
render(<Booker {...(propsWithQuickChecks as unknown as BookerProps & WrappedBookerProps)} />, {
|
||||
mockStore: { state: "booking" },
|
||||
});
|
||||
const bookEventForm = screen.getByTestId("book-event-form");
|
||||
await expect(bookEventForm).toHaveAttribute("data-unavailable", "true");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -18,6 +18,7 @@ import type { BookerProps, WrappedBookerProps } from "@calcom/features/bookings/
|
||||
import { isBookingDryRun } from "@calcom/features/bookings/Booker/utils/isBookingDryRun";
|
||||
import { isTimeSlotAvailable } from "@calcom/features/bookings/Booker/utils/isTimeslotAvailable";
|
||||
import { getQueryParam } from "@calcom/features/bookings/Booker/utils/query-param";
|
||||
import { Dialog } from "@calcom/features/components/controlled-dialog";
|
||||
import { useNonEmptyScheduleDays } from "@calcom/features/schedules/lib/use-schedule/useNonEmptyScheduleDays";
|
||||
import { scrollIntoViewSmooth } from "@calcom/lib/browser/browser.utils";
|
||||
import {
|
||||
@@ -28,6 +29,7 @@ import {
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
import { BookerLayouts } from "@calcom/prisma/zod-utils";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
import { DialogContent } from "@calcom/ui/components/dialog";
|
||||
import { UnpublishedEntity } from "@calcom/ui/components/unpublished-entity";
|
||||
import PoweredBy from "@calcom/web/modules/ee/common/components/PoweredBy";
|
||||
import { AnimatePresence, LazyMotion, m } from "framer-motion";
|
||||
@@ -48,6 +50,7 @@ import { LargeCalendar } from "./LargeCalendar";
|
||||
import { OverlayCalendar } from "./OverlayCalendar/OverlayCalendar";
|
||||
import { RedirectToInstantMeetingModal } from "./RedirectToInstantMeetingModal";
|
||||
import { BookerSection } from "./Section";
|
||||
import { SlotSelectionModalHeader } from "./SlotSelectionModalHeader";
|
||||
import { NotFound } from "./Unavailable";
|
||||
import { VerifyCodeDialog } from "./VerifyCodeDialog";
|
||||
|
||||
@@ -99,6 +102,11 @@ const BookerComponent = ({
|
||||
|
||||
const selectedDate = useBookerStoreContext((state) => state.selectedDate);
|
||||
|
||||
const [isSlotSelectionModalVisible, setIsSlotSelectionModalVisible] = useBookerStoreContext(
|
||||
(state) => [state.isSlotSelectionModalVisible, state.setIsSlotSelectionModalVisible],
|
||||
shallow
|
||||
);
|
||||
|
||||
const {
|
||||
shouldShowFormInDialog,
|
||||
hasDarkBackground,
|
||||
@@ -109,6 +117,7 @@ const BookerComponent = ({
|
||||
hideEventTypeDetails,
|
||||
isEmbed,
|
||||
bookerLayouts,
|
||||
slotsViewOnSmallScreen,
|
||||
} = bookerLayout;
|
||||
|
||||
const [seatedEventData, setSeatedEventData] = useBookerStoreContext(
|
||||
@@ -181,6 +190,11 @@ const BookerComponent = ({
|
||||
const scrolledToTimeslotsOnce = useRef(false);
|
||||
const embedUiConfig = useEmbedUiConfig();
|
||||
const scrollToTimeSlots = () => {
|
||||
// Don't scroll if slots view on small screen is enabled
|
||||
if (slotsViewOnSmallScreen) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
isMobile &&
|
||||
!scrolledToTimeslotsOnce.current &&
|
||||
@@ -213,6 +227,10 @@ const BookerComponent = ({
|
||||
|
||||
const onAvailableTimeSlotSelect = (time: string) => {
|
||||
setSelectedTimeslot(time);
|
||||
|
||||
if (!skipConfirmStep) {
|
||||
setIsSlotSelectionModalVisible(false);
|
||||
}
|
||||
};
|
||||
|
||||
updateEmbedBookerState({ bookerState, slotsQuery: schedule });
|
||||
@@ -268,7 +286,11 @@ const BookerComponent = ({
|
||||
schedule?.invalidate();
|
||||
}
|
||||
if (seatedEventData.bookingUid) {
|
||||
setSeatedEventData({ ...seatedEventData, bookingUid: undefined, attendees: undefined });
|
||||
setSeatedEventData({
|
||||
...seatedEventData,
|
||||
bookingUid: undefined,
|
||||
attendees: undefined,
|
||||
});
|
||||
}
|
||||
}}
|
||||
onSubmit={() => (renderConfirmNotVerifyEmailButtonCond ? handleBookEvent() : handleVerifyEmail())}
|
||||
@@ -460,6 +482,11 @@ const BookerComponent = ({
|
||||
isLoading={schedule.isPending}
|
||||
scrollToTimeSlots={scrollToTimeSlots}
|
||||
showNoAvailabilityDialog={showNoAvailabilityDialog}
|
||||
onDateChange={() => {
|
||||
if (slotsViewOnSmallScreen) {
|
||||
setIsSlotSelectionModalVisible(true);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
@@ -493,7 +520,7 @@ const BookerComponent = ({
|
||||
</BookerSection>
|
||||
|
||||
<BookerSection
|
||||
key="large-calendar"
|
||||
key="enable-calendar"
|
||||
area="main"
|
||||
visible={layout === BookerLayouts.WEEK_VIEW}
|
||||
className="border-subtle sticky top-0 -ml-px h-full md:border-l"
|
||||
@@ -505,12 +532,14 @@ const BookerComponent = ({
|
||||
event={event}
|
||||
/>
|
||||
</BookerSection>
|
||||
|
||||
<BookerSection
|
||||
key="timeslots"
|
||||
area={{ default: "main", month_view: "timeslots" }}
|
||||
visible={
|
||||
(layout !== BookerLayouts.WEEK_VIEW && bookerState === "selecting_time") ||
|
||||
layout === BookerLayouts.COLUMN_VIEW
|
||||
!(slotsViewOnSmallScreen && isMobile) &&
|
||||
((layout !== BookerLayouts.WEEK_VIEW && bookerState === "selecting_time") ||
|
||||
layout === BookerLayouts.COLUMN_VIEW)
|
||||
}
|
||||
className={classNames(
|
||||
"border-subtle rtl:border-default flex h-full w-full flex-col overflow-x-auto px-5 py-3 pb-0 rtl:border-r ltr:md:border-l",
|
||||
@@ -618,6 +647,42 @@ const BookerComponent = ({
|
||||
visible={bookerState === "booking" && shouldShowFormInDialog}>
|
||||
{EventBooker}
|
||||
</BookFormAsModal>
|
||||
<Dialog open={isMobile && isSlotSelectionModalVisible}>
|
||||
<DialogContent
|
||||
type={undefined}
|
||||
enableOverflow
|
||||
className="fixed! inset-0! top-0! left-0! h-screen! max-h-screen! w-screen! max-w-none! translate-x-0! translate-y-0! rounded-none! m-0! px-8 pt-0 pb-8">
|
||||
<SlotSelectionModalHeader
|
||||
onClick={() => setIsSlotSelectionModalVisible(false)}
|
||||
event={event.data}
|
||||
isPlatform={isPlatform}
|
||||
timeZones={timeZones}
|
||||
selectedDate={selectedDate}
|
||||
/>
|
||||
<AvailableTimeSlots
|
||||
onAvailableTimeSlotSelect={onAvailableTimeSlotSelect}
|
||||
customClassNames={customClassNames?.availableTimeSlotsCustomClassNames}
|
||||
extraDays={extraDays}
|
||||
limitHeight={layout === BookerLayouts.MONTH_VIEW}
|
||||
schedule={schedule}
|
||||
isLoading={schedule.isPending}
|
||||
seatsPerTimeSlot={event.data?.seatsPerTimeSlot}
|
||||
unavailableTimeSlots={unavailableTimeSlots}
|
||||
showAvailableSeatsCount={event.data?.seatsShowAvailabilityCount}
|
||||
event={event}
|
||||
loadingStates={loadingStates}
|
||||
renderConfirmNotVerifyEmailButtonCond={renderConfirmNotVerifyEmailButtonCond}
|
||||
isVerificationCodeSending={isVerificationCodeSending}
|
||||
onSubmit={onSubmit}
|
||||
skipConfirmStep={skipConfirmStep}
|
||||
shouldRenderCaptcha={shouldRenderCaptcha}
|
||||
watchedCfToken={watchedCfToken}
|
||||
confirmButtonDisabled={confirmButtonDisabled}
|
||||
confirmStepClassNames={customClassNames?.confirmStep}
|
||||
hideAvailableTimesHeader
|
||||
/>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<Toaster position="bottom-right" />
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -6,10 +6,7 @@ import { useMemo, useCallback, useEffect } from "react";
|
||||
import React from "react";
|
||||
import { shallow } from "zustand/shallow";
|
||||
|
||||
import {
|
||||
sdkActionManager,
|
||||
useIsEmbed,
|
||||
} from "@calcom/embed-core/embed-iframe";
|
||||
import { sdkActionManager, useIsEmbed } from "@calcom/embed-core/embed-iframe";
|
||||
import { useBookerEmbedEvents } from "@calcom/embed-core/src/embed-iframe/react-hooks";
|
||||
import type { BookerProps } from "@calcom/features/bookings/Booker";
|
||||
import {
|
||||
@@ -25,10 +22,17 @@ import { useSlots } from "@calcom/features/bookings/Booker/components/hooks/useS
|
||||
import { useVerifyCode } from "@calcom/features/bookings/Booker/components/hooks/useVerifyCode";
|
||||
import { useVerifyEmail } from "@calcom/features/bookings/Booker/components/hooks/useVerifyEmail";
|
||||
import { useInitializeBookerStore } from "@calcom/features/bookings/Booker/store";
|
||||
import { useEvent, useScheduleForEvent } from "@calcom/features/bookings/Booker/utils/event";
|
||||
import {
|
||||
useEvent,
|
||||
useScheduleForEvent,
|
||||
} from "@calcom/features/bookings/Booker/utils/event";
|
||||
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 {
|
||||
DEFAULT_LIGHT_BRAND_COLOR,
|
||||
DEFAULT_DARK_BRAND_COLOR,
|
||||
WEBAPP_URL,
|
||||
} from "@calcom/lib/constants";
|
||||
import { useRouterQuery } from "@calcom/lib/hooks/useRouterQuery";
|
||||
import { localStorage } from "@calcom/lib/webstorage";
|
||||
|
||||
@@ -48,11 +52,11 @@ const BookerWebWrapperComponent = (props: BookerWebWrapperAtomProps) => {
|
||||
});
|
||||
const event = props.eventData
|
||||
? {
|
||||
data: props.eventData,
|
||||
isSuccess: true,
|
||||
isError: false,
|
||||
isPending: false,
|
||||
}
|
||||
data: props.eventData,
|
||||
isSuccess: true,
|
||||
isError: false,
|
||||
isPending: false,
|
||||
}
|
||||
: clientFetchedEvent;
|
||||
|
||||
const bookerLayout = useBookerLayout(event.data?.profile?.bookerLayouts);
|
||||
@@ -60,11 +64,17 @@ const BookerWebWrapperComponent = (props: BookerWebWrapperAtomProps) => {
|
||||
const isRedirect = searchParams?.get("redirected") === "true" || false;
|
||||
const fromUserNameRedirected = searchParams?.get("username") || "";
|
||||
const rescheduleUid =
|
||||
typeof window !== "undefined" ? new URLSearchParams(window.location.search).get("rescheduleUid") : null;
|
||||
typeof window !== "undefined"
|
||||
? new URLSearchParams(window.location.search).get("rescheduleUid")
|
||||
: null;
|
||||
const rescheduledBy =
|
||||
typeof window !== "undefined" ? new URLSearchParams(window.location.search).get("rescheduledBy") : null;
|
||||
typeof window !== "undefined"
|
||||
? new URLSearchParams(window.location.search).get("rescheduledBy")
|
||||
: null;
|
||||
const bookingUid =
|
||||
typeof window !== "undefined" ? new URLSearchParams(window.location.search).get("bookingUid") : null;
|
||||
typeof window !== "undefined"
|
||||
? new URLSearchParams(window.location.search).get("bookingUid")
|
||||
: null;
|
||||
const timezone = searchParams?.get("cal.tz") || null;
|
||||
|
||||
useEffect(() => {
|
||||
@@ -92,7 +102,10 @@ const BookerWebWrapperComponent = (props: BookerWebWrapperAtomProps) => {
|
||||
timezone,
|
||||
});
|
||||
|
||||
const [dayCount] = useBookerStoreContext((state) => [state.dayCount, state.setDayCount], shallow);
|
||||
const [dayCount] = useBookerStoreContext(
|
||||
(state) => [state.dayCount, state.setDayCount],
|
||||
shallow
|
||||
);
|
||||
|
||||
const { data: session } = useSession();
|
||||
const routerQuery = useRouterQuery();
|
||||
@@ -104,7 +117,8 @@ const BookerWebWrapperComponent = (props: BookerWebWrapperAtomProps) => {
|
||||
.reduce(
|
||||
(metadata, key) => ({
|
||||
...metadata,
|
||||
[key.substring("metadata[".length, key.length - 1)]: searchParams?.get(key),
|
||||
[key.substring("metadata[".length, key.length - 1)]:
|
||||
searchParams?.get(key),
|
||||
}),
|
||||
{}
|
||||
);
|
||||
@@ -112,8 +126,11 @@ const BookerWebWrapperComponent = (props: BookerWebWrapperAtomProps) => {
|
||||
return {
|
||||
name:
|
||||
searchParams?.get("name") ||
|
||||
(firstNameQueryParam ? `${firstNameQueryParam} ${lastNameQueryParam}` : null),
|
||||
guests: (searchParams?.getAll("guests") || searchParams?.getAll("guest")) ?? [],
|
||||
(firstNameQueryParam
|
||||
? `${firstNameQueryParam} ${lastNameQueryParam}`
|
||||
: null),
|
||||
guests:
|
||||
(searchParams?.getAll("guests") || searchParams?.getAll("guest")) ?? [],
|
||||
};
|
||||
}, [searchParams, firstNameQueryParam, lastNameQueryParam]);
|
||||
|
||||
@@ -130,10 +147,13 @@ const BookerWebWrapperComponent = (props: BookerWebWrapperAtomProps) => {
|
||||
const verifyEmail = useVerifyEmail({
|
||||
email: bookerForm.formEmail,
|
||||
name: bookerForm.formName,
|
||||
requiresBookerEmailVerification: event?.data?.requiresBookerEmailVerification,
|
||||
requiresBookerEmailVerification:
|
||||
event?.data?.requiresBookerEmailVerification,
|
||||
onVerifyEmail: bookerForm.beforeVerifyEmail,
|
||||
});
|
||||
const slots = useSlots(event?.data ? { id: event.data.id, length: event.data.length } : null);
|
||||
const slots = useSlots(
|
||||
event?.data ? { id: event.data.id, length: event.data.length } : null
|
||||
);
|
||||
|
||||
const isEmbed = useIsEmbed();
|
||||
|
||||
@@ -197,16 +217,17 @@ const BookerWebWrapperComponent = (props: BookerWebWrapperAtomProps) => {
|
||||
);
|
||||
useBrandColors({
|
||||
brandColor: event.data?.profile.brandColor ?? DEFAULT_LIGHT_BRAND_COLOR,
|
||||
darkBrandColor: event.data?.profile.darkBrandColor ?? DEFAULT_DARK_BRAND_COLOR,
|
||||
darkBrandColor:
|
||||
event.data?.profile.darkBrandColor ?? DEFAULT_DARK_BRAND_COLOR,
|
||||
theme: event.data?.profile.theme,
|
||||
});
|
||||
|
||||
const areInstantMeetingParametersSet = Boolean(
|
||||
event.data?.instantMeetingParameters &&
|
||||
searchParams &&
|
||||
event.data.instantMeetingParameters?.every?.((param) =>
|
||||
Array.from(searchParams.values()).includes(param)
|
||||
)
|
||||
searchParams &&
|
||||
event.data.instantMeetingParameters?.every?.((param) =>
|
||||
Array.from(searchParams.values()).includes(param)
|
||||
)
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -10,6 +10,7 @@ import { weekdayToWeekIndex } from "@calcom/lib/dayjs";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { User } from "@calcom/prisma/client";
|
||||
import type { PeriodData } from "@calcom/types/Event";
|
||||
import { useSlotsViewOnSmallScreen } from "@calcom/features/bookings/Booker/components/hooks/useSlotsViewOnSmallScreen";
|
||||
|
||||
import type { Slots } from "@calcom/features/bookings/types";
|
||||
|
||||
@@ -32,8 +33,8 @@ const useMoveToNextMonthOnNoAvailability = ({
|
||||
};
|
||||
}
|
||||
|
||||
const nonEmptyScheduleDaysInBrowsingMonth = nonEmptyScheduleDays.filter((date) =>
|
||||
dayjs(date).isSame(browsingDate, "month")
|
||||
const nonEmptyScheduleDaysInBrowsingMonth = nonEmptyScheduleDays.filter(
|
||||
(date) => dayjs(date).isSame(browsingDate, "month")
|
||||
);
|
||||
|
||||
const moveToNextMonthOnNoAvailability = () => {
|
||||
@@ -41,7 +42,10 @@ const useMoveToNextMonthOnNoAvailability = ({
|
||||
const browsingMonth = browsingDate.format("YYYY-MM");
|
||||
// Not meeting the criteria to move to next month
|
||||
// Has to be currentMonth and it must have all days unbookable
|
||||
if (currentMonth != browsingMonth || nonEmptyScheduleDaysInBrowsingMonth.length) {
|
||||
if (
|
||||
currentMonth != browsingMonth ||
|
||||
nonEmptyScheduleDaysInBrowsingMonth.length
|
||||
) {
|
||||
return;
|
||||
}
|
||||
onMonthChange(browsingDate.add(1, "month"));
|
||||
@@ -58,6 +62,7 @@ export const DatePicker = ({
|
||||
classNames,
|
||||
scrollToTimeSlots,
|
||||
showNoAvailabilityDialog,
|
||||
onDateChange,
|
||||
}: {
|
||||
event: {
|
||||
data?: {
|
||||
@@ -74,6 +79,7 @@ export const DatePicker = ({
|
||||
classNames?: DatePickerClassNames;
|
||||
scrollToTimeSlots?: () => void;
|
||||
showNoAvailabilityDialog?: boolean;
|
||||
onDateChange?: () => void;
|
||||
}) => {
|
||||
const { i18n } = useLocale();
|
||||
const [month, selectedDate, layout] = useBookerStoreContext(
|
||||
@@ -86,21 +92,26 @@ export const DatePicker = ({
|
||||
shallow
|
||||
);
|
||||
|
||||
const slotsViewOnSmallScreen = useSlotsViewOnSmallScreen();
|
||||
|
||||
const onMonthChange = (date: Dayjs) => {
|
||||
setMonth(date.format("YYYY-MM"));
|
||||
setSelectedDate({ date: date.format("YYYY-MM-DD") });
|
||||
if (!slotsViewOnSmallScreen) {
|
||||
setSelectedDate({ date: date.format("YYYY-MM-DD") });
|
||||
}
|
||||
setDayCount(null); // Whenever the month is changed, we nullify getting X days
|
||||
};
|
||||
|
||||
const nonEmptyScheduleDays = useNonEmptyScheduleDays(slots);
|
||||
const browsingDate = month ? dayjs(month) : dayjs().startOf("month");
|
||||
|
||||
const { moveToNextMonthOnNoAvailability } = useMoveToNextMonthOnNoAvailability({
|
||||
browsingDate,
|
||||
nonEmptyScheduleDays,
|
||||
onMonthChange,
|
||||
isLoading: isLoading ?? true,
|
||||
});
|
||||
const { moveToNextMonthOnNoAvailability } =
|
||||
useMoveToNextMonthOnNoAvailability({
|
||||
browsingDate,
|
||||
nonEmptyScheduleDays,
|
||||
onMonthChange,
|
||||
isLoading: isLoading ?? true,
|
||||
});
|
||||
moveToNextMonthOnNoAvailability();
|
||||
|
||||
// Determine if this is a compact sidebar view based on layout
|
||||
@@ -134,11 +145,19 @@ export const DatePicker = ({
|
||||
className={classNames?.datePickerContainer}
|
||||
isLoading={isLoading}
|
||||
onChange={(date: Dayjs | null, omitUpdatingParams?: boolean) => {
|
||||
const newDate = date === null ? null : date.format("YYYY-MM-DD");
|
||||
const previousDate = selectedDate;
|
||||
const dateChanged = newDate !== previousDate;
|
||||
|
||||
setSelectedDate({
|
||||
date: date === null ? date : date.format("YYYY-MM-DD"),
|
||||
date: date === null ? null : date.format("YYYY-MM-DD"),
|
||||
omitUpdatingParams,
|
||||
preventMonthSwitching: !isCompact, // Prevent month switching when in monthly view
|
||||
});
|
||||
|
||||
if (dateChanged) {
|
||||
onDateChange?.();
|
||||
}
|
||||
}}
|
||||
onMonthChange={onMonthChange}
|
||||
includedDates={nonEmptyScheduleDays}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
import dynamic from "next/dynamic";
|
||||
import { useMemo } from "react";
|
||||
import { shallow } from "zustand/shallow";
|
||||
|
||||
import { Timezone as PlatformTimezoneSelect } from "@calcom/atoms/timezone";
|
||||
import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider";
|
||||
import type { Timezone } from "@calcom/features/bookings/Booker/types";
|
||||
import type { BookerEvent } from "@calcom/features/bookings/types";
|
||||
import { EventDetailBlocks } from "@calcom/features/bookings/types";
|
||||
import { useTimePreferences } from "@calcom/features/bookings/lib";
|
||||
import { CURRENT_TIMEZONE } from "@calcom/lib/timezoneConstants";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { Icon } from "@calcom/ui/components/icon";
|
||||
|
||||
import { EventDetails } from "./event-meta/Details";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
const LoadingState = () => {
|
||||
const { t } = useLocale();
|
||||
return <span className="text-default text-sm">{t("loading")}</span>;
|
||||
};
|
||||
|
||||
const WebTimezoneSelect = dynamic(
|
||||
() =>
|
||||
import("@calcom/features/components/timezone-select").then(
|
||||
(mod) => mod.TimezoneSelect
|
||||
),
|
||||
{
|
||||
ssr: false,
|
||||
loading: () => <LoadingState />,
|
||||
}
|
||||
);
|
||||
|
||||
type SlotSelectionModalHeaderProps = {
|
||||
onClick: () => void;
|
||||
event?: Pick<
|
||||
BookerEvent,
|
||||
| "length"
|
||||
| "metadata"
|
||||
| "lockTimeZoneToggleOnBookingPage"
|
||||
| "lockedTimeZone"
|
||||
| "isDynamic"
|
||||
| "currency"
|
||||
| "price"
|
||||
| "locations"
|
||||
| "requiresConfirmation"
|
||||
| "recurringEvent"
|
||||
> | null;
|
||||
isPlatform?: boolean;
|
||||
timeZones?: Timezone[];
|
||||
selectedDate: string | null;
|
||||
};
|
||||
|
||||
export const SlotSelectionModalHeader = ({
|
||||
onClick,
|
||||
event,
|
||||
isPlatform = false,
|
||||
timeZones,
|
||||
selectedDate,
|
||||
}: SlotSelectionModalHeaderProps) => {
|
||||
const { i18n } = useLocale();
|
||||
const [setTimezone] = useTimePreferences((state) => [state.setTimezone]);
|
||||
const [timezone, setBookerStoreTimezone] = useBookerStoreContext(
|
||||
(state) => [state.timezone, state.setTimezone],
|
||||
shallow
|
||||
);
|
||||
const [TimezoneSelect] = useMemo(
|
||||
() => (isPlatform ? [PlatformTimezoneSelect] : [WebTimezoneSelect]),
|
||||
[isPlatform]
|
||||
);
|
||||
|
||||
const formattedDate = useMemo(() => {
|
||||
if (!selectedDate) return { dayOfWeek: "", fullDate: "" };
|
||||
const date = new Date(selectedDate);
|
||||
const dayOfWeek = date.toLocaleDateString(i18n.language, {
|
||||
weekday: "long",
|
||||
});
|
||||
const fullDate = date.toLocaleDateString(i18n.language, {
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
year: "numeric",
|
||||
});
|
||||
return { dayOfWeek, fullDate };
|
||||
}, [selectedDate, i18n.language]);
|
||||
|
||||
return (
|
||||
<div className="two-step-slot-selection-modal-header bg-default border-subtle sticky top-0 z-10 flex flex-col mb-4 mt-0 border-b pb-4 -mx-4 px-8">
|
||||
<div className="flex flex-col gap-2 pt-8">
|
||||
<div className="flex flex-col">
|
||||
<span className="text-emphasis text-lg font-semibold">
|
||||
<Button
|
||||
color="minimal"
|
||||
StartIcon="arrow-left"
|
||||
className="mb-2 ml-[-42px] w-[40px]"
|
||||
onClick={onClick}
|
||||
/>{" "}
|
||||
{formattedDate.dayOfWeek}
|
||||
</span>
|
||||
<span className="text-default text-sm">{formattedDate.fullDate}</span>
|
||||
</div>
|
||||
|
||||
{event && (
|
||||
<EventDetails event={event} blocks={[EventDetailBlocks.DURATION]} />
|
||||
)}
|
||||
|
||||
<div className="text-default flex items-center gap-2 text-sm mb-0">
|
||||
<Icon name="globe" className="text-subtle h-4 w-4 shrink-0" />
|
||||
{TimezoneSelect && (
|
||||
<span className="min-w-32 -mt-[2px] flex h-6 max-w-full items-center justify-start">
|
||||
<TimezoneSelect
|
||||
timeZones={timeZones}
|
||||
menuPosition="fixed"
|
||||
classNames={{
|
||||
control: () =>
|
||||
"min-h-0! p-0 w-full border-0 bg-transparent focus-within:ring-0 shadow-none!",
|
||||
menu: () => "w-64! max-w-[90vw] mb-1",
|
||||
singleValue: () => "text-text py-1",
|
||||
indicatorsContainer: () => "ml-auto",
|
||||
container: () => "max-w-full",
|
||||
}}
|
||||
value={
|
||||
event?.lockTimeZoneToggleOnBookingPage
|
||||
? event.lockedTimeZone || CURRENT_TIMEZONE
|
||||
: timezone || CURRENT_TIMEZONE
|
||||
}
|
||||
onChange={({ value }) => {
|
||||
setTimezone(value);
|
||||
setBookerStoreTimezone(value);
|
||||
}}
|
||||
isDisabled={event?.lockTimeZoneToggleOnBookingPage}
|
||||
/>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -228,7 +228,9 @@ const ChooseEmbedTypesDialogContent = ({
|
||||
return (
|
||||
<DialogContent className="rounded-lg p-10" type="creation" size="lg">
|
||||
<div className="mb-2">
|
||||
<h3 className="font-cal text-emphasis mb-2 text-2xl font-semibold leading-none" id="modal-title">
|
||||
<h3
|
||||
className="font-cal text-emphasis mb-2 text-2xl font-semibold leading-none"
|
||||
id="modal-title">
|
||||
{t("how_you_want_add_cal_site", { appName: APP_NAME })}
|
||||
</h3>
|
||||
<div>
|
||||
@@ -864,6 +866,7 @@ const EmbedTypeCodeAndPreviewDialogContent = ({
|
||||
useState(true);
|
||||
const defaultConfig = {
|
||||
layout: BookerLayouts.MONTH_VIEW,
|
||||
useSlotsViewOnSmallScreen: "true" as const,
|
||||
};
|
||||
|
||||
const paletteDefaultValue = (paletteName: string) => {
|
||||
|
||||
@@ -7,6 +7,20 @@ global.React = React;
|
||||
global.ResizeObserver = ResizeObserver;
|
||||
expect.extend(matchers);
|
||||
|
||||
Object.defineProperty(window, "matchMedia", {
|
||||
writable: true,
|
||||
value: vi.fn().mockImplementation((query: string) => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
})),
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user