* refactor: move Booker hooks from packages/features to apps/web/modules Migrate the following Booker hooks: - useOverlayCalendar - useSkipConfirmStep - useInitializeWeekStart - useIsQuickAvailabilityCheckFeatureEnabled - useDecoyBooking These hooks are only imported by apps/web files, making them safe to move without creating circular dependencies. Part of the tRPC-driven UI migration from packages/features to apps/web/modules. Co-Authored-By: [email protected] <[email protected]> * fix: revert useIsQuickAvailabilityCheckFeatureEnabled move and fix import paths - Reverted useIsQuickAvailabilityCheckFeatureEnabled.ts back to packages/features since it's imported by useSlots.ts in packages/features (would create circular dependency) - Fixed import paths in useOverlayCalendar.ts to use @calcom/features paths - Fixed import paths in useSkipConfirmStep.ts to use @calcom/features paths - Updated Booker.tsx to import useIsQuickAvailabilityCheckFeatureEnabled from original location Co-Authored-By: [email protected] <[email protected]> * fix: use @calcom/web alias for hook imports to fix vitest resolution Co-Authored-By: [email protected] <[email protected]> * refactor * migrate more hooks * fix * mv types * fix * fix * fix * fix * revert: remove formatting-only changes to make PR easier to review Co-Authored-By: [email protected] <[email protected]> * fix * fix * fix * revert: restore original import ordering in moved hooks Co-Authored-By: [email protected] <[email protected]> * fix imports * fix * fix * wip * wip * wip * wip * wip * wip * fix: add isBrowser guard to useSlotsViewOnSmallScreen hook Address Cubic AI review feedback (confidence 9/10) by adding the isBrowser guard to the useSlotsViewOnSmallScreen hook to follow the file's client-only contract and avoid executing during SSR/prerendering. Co-Authored-By: unknown <> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
106 lines
4.3 KiB
TypeScript
106 lines
4.3 KiB
TypeScript
import { useEffect, useRef } from "react";
|
|
import { shallow } from "zustand/shallow";
|
|
|
|
import {
|
|
useEmbedType,
|
|
useEmbedUiConfig,
|
|
useIsEmbed,
|
|
useSlotsViewOnSmallScreen,
|
|
} from "@calcom/embed-core/embed-iframe";
|
|
import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider";
|
|
import { extraDaysConfig } from "@calcom/features/bookings/Booker/config";
|
|
import type { BookerLayout } from "@calcom/features/bookings/Booker/types";
|
|
import { validateLayout } from "@calcom/features/bookings/Booker/utils/layout";
|
|
import { getQueryParam } from "@calcom/features/bookings/Booker/utils/query-param";
|
|
import type { BookerEvent } from "@calcom/features/bookings/types";
|
|
import useMediaQuery from "@calcom/lib/hooks/useMediaQuery";
|
|
import type { BookerLayouts } from "@calcom/prisma/zod-utils";
|
|
import { defaultBookerLayoutSettings } from "@calcom/prisma/zod-utils";
|
|
|
|
export type UseBookerLayoutType = ReturnType<typeof useBookerLayout>;
|
|
|
|
export const useBookerLayout = (
|
|
profileBookerLayouts: BookerEvent["profile"]["bookerLayouts"] | undefined | null
|
|
) => {
|
|
const [_layout, setLayout] = useBookerStoreContext((state) => [state.layout, state.setLayout], shallow);
|
|
const isEmbed = useIsEmbed();
|
|
const isMobile = useMediaQuery("(max-width: 768px)");
|
|
const isTablet = useMediaQuery("(max-width: 1024px)");
|
|
const embedUiConfig = useEmbedUiConfig();
|
|
// In Embed we give preference to embed configuration for the layout.If that's not set, we use the App configuration for the event layout
|
|
// But if it's mobile view, there is only one layout supported which is 'mobile'
|
|
const layout = isEmbed ? (isMobile ? "mobile" : validateLayout(embedUiConfig.layout) || _layout) : _layout;
|
|
const extraDays = isTablet ? extraDaysConfig[layout].tablet : extraDaysConfig[layout].desktop;
|
|
const embedType = useEmbedType();
|
|
// Floating Button and Element Click both are modal and thus have dark background
|
|
const hasDarkBackground = isEmbed && embedType !== "inline";
|
|
const columnViewExtraDays = useRef<number>(
|
|
isTablet ? extraDaysConfig[layout].tablet : extraDaysConfig[layout].desktop
|
|
);
|
|
const bookerLayouts = profileBookerLayouts || defaultBookerLayoutSettings;
|
|
const defaultLayout = isEmbed
|
|
? validateLayout(embedUiConfig.layout) || bookerLayouts.defaultLayout
|
|
: bookerLayouts.defaultLayout;
|
|
|
|
useEffect(() => {
|
|
if (isMobile && layout !== "mobile") {
|
|
setLayout("mobile");
|
|
} else if (!isMobile && layout === "mobile") {
|
|
setLayout(defaultLayout);
|
|
}
|
|
}, [isMobile, setLayout, layout, defaultLayout]);
|
|
//setting layout from query param
|
|
useEffect(() => {
|
|
const layout = getQueryParam("layout") as BookerLayouts;
|
|
if (
|
|
!isMobile &&
|
|
!isEmbed &&
|
|
validateLayout(layout) &&
|
|
bookerLayouts?.enabledLayouts?.length &&
|
|
layout !== _layout
|
|
) {
|
|
const validLayout = bookerLayouts.enabledLayouts.find((userLayout) => userLayout === layout);
|
|
if (validLayout) setLayout(validLayout);
|
|
}
|
|
}, [bookerLayouts, setLayout, _layout, isEmbed, isMobile]);
|
|
|
|
// In Embed, a Dialog doesn't look good, we disable it intentionally for the layouts that support showing Form without Dialog(i.e. no-dialog Form)
|
|
const shouldShowFormInDialogMap: Record<BookerLayout, boolean> = {
|
|
// mobile supports showing the Form without Dialog
|
|
mobile: !isEmbed,
|
|
// We don't show Dialog in month_view currently. Can be easily toggled though as it supports no-dialog Form
|
|
month_view: false,
|
|
// week_view doesn't support no-dialog Form
|
|
// When it's supported, disable it for embed
|
|
week_view: true,
|
|
// column_view doesn't support no-dialog Form
|
|
// When it's supported, disable it for embed
|
|
column_view: true,
|
|
};
|
|
|
|
const shouldShowFormInDialog = shouldShowFormInDialogMap[layout];
|
|
|
|
const hideEventTypeDetailsParam = getQueryParam("hideEventTypeDetails");
|
|
const hideEventTypeDetails = isEmbed
|
|
? embedUiConfig.hideEventTypeDetails
|
|
: typeof hideEventTypeDetailsParam === "string"
|
|
? hideEventTypeDetailsParam === "true"
|
|
: false;
|
|
|
|
const slotsViewOnSmallScreen = useSlotsViewOnSmallScreen();
|
|
|
|
return {
|
|
shouldShowFormInDialog,
|
|
hasDarkBackground,
|
|
extraDays,
|
|
columnViewExtraDays,
|
|
isMobile,
|
|
isEmbed,
|
|
isTablet,
|
|
layout,
|
|
defaultLayout,
|
|
hideEventTypeDetails,
|
|
slotsViewOnSmallScreen,
|
|
bookerLayouts,
|
|
};
|
|
}; |