* fix manage test error * fix manage test error * update useBookerContext * wrap store provider around booker * replace useStore with useBookerStoreContext * replace useBookerStore with useBookerStoreContext * add initializer function for booker store provider * update props * fixup: pass more props * export StoreInitializeType type * replace useBookerStore with useBookerStoreContext * fixup: dont wrap BookerStoreProvider around booker directly * wrap BookerStoreProvider around booker web wrapper and fix local storage import * fix: wrap test components with BookerStoreProvider to fix failing unit tests - Create reusable test utility in test-utils.tsx with comprehensive mock store - Update Booker.test.tsx to use context-based testing approach - Fix DatePicker tests in both bookings and calendars packages - Simulate auto-advance behavior for month navigation tests - All 14 previously failing tests now pass Co-Authored-By: rajiv@cal.com <sahalrajiv6900@gmail.com> * add changesets * fix: complete migration from useBookerStore to useBookerStoreContext - Updated all remaining files to use useBookerStoreContext instead of useBookerStore - Fixed BookingFields.test.tsx by wrapping test component with BookerStoreProvider - Ensures all Booker components work within the new context-based store pattern - Resolves failing unit tests in CI by completing the store migration Co-Authored-By: rajiv@cal.com <sahalrajiv6900@gmail.com> * fix: add missing useBookerStoreContext import in BookerWebWrapper.tsx - Fixes TypeScript errors in CI where useBookerStoreContext was used but not imported - Completes the migration from useBookerStore to useBookerStoreContext pattern - All tests pass locally after this fix Co-Authored-By: rajiv@cal.com <sahalrajiv6900@gmail.com> * Revert "fix: add missing useBookerStoreContext import in BookerWebWrapper.tsx" This reverts commit 12947ca63f46c42e5aee74c78176ef230e2bf2cf. * Revert "fix: complete migration from useBookerStore to useBookerStoreContext" This reverts commit 87d837f2d30e4f9259d2be786049d21856f4eef0. * fixup: useBookerStoreContext and useInitializeBookerStoreContext for booker web wrapper * fixup: failing E2E tests * fixup: email embed breaking * fixup: troubleshooter crashing * replace useBookerstore with useBookerStoreContext --------- Co-authored-by: Rajiv Sahal <sahalrajiv-extc@atharvacoe.ac.in> Co-authored-by: Ryukemeister <sahalrajiv6900@gmail.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Benny Joo <sldisek783@gmail.com>
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import type { MotionProps } from "framer-motion";
|
|
import { m } from "framer-motion";
|
|
import { forwardRef } from "react";
|
|
|
|
import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider";
|
|
import classNames from "@calcom/ui/classNames";
|
|
|
|
import type { BookerAreas, BookerLayout } from "../types";
|
|
|
|
/**
|
|
* Define what grid area a section should be in.
|
|
* Value is either a string (in case it's always the same area), or an object
|
|
* looking like:
|
|
* {
|
|
* // Where default is the required default area.
|
|
* default: "calendar",
|
|
* // Any optional overrides for different layouts by their layout name.
|
|
* week_view: "main",
|
|
* }
|
|
*/
|
|
type GridArea = BookerAreas | ({ [key in BookerLayout]?: BookerAreas } & { default: BookerAreas });
|
|
|
|
type BookerSectionProps = {
|
|
children: React.ReactNode;
|
|
area: GridArea;
|
|
visible?: boolean;
|
|
className?: string;
|
|
} & MotionProps;
|
|
|
|
// This map with strings is needed so Tailwind generates all classnames,
|
|
// If we would concatenate them with JS, Tailwind would not generate them.
|
|
const gridAreaClassNameMap: { [key in BookerAreas]: string } = {
|
|
calendar: "[grid-area:calendar]",
|
|
main: "[grid-area:main]",
|
|
meta: "[grid-area:meta]",
|
|
timeslots: "[grid-area:timeslots]",
|
|
header: "[grid-area:header]",
|
|
};
|
|
|
|
/**
|
|
* Small helper component that renders a booker section in a specific grid area.
|
|
*/
|
|
export const BookerSection = forwardRef<HTMLDivElement, BookerSectionProps>(function BookerSection(
|
|
{ children, area, visible, className, ...props },
|
|
ref
|
|
) {
|
|
const layout = useBookerStoreContext((state) => state.layout);
|
|
let gridClassName: string;
|
|
|
|
if (typeof area === "string") {
|
|
gridClassName = gridAreaClassNameMap[area];
|
|
} else {
|
|
gridClassName = gridAreaClassNameMap[area[layout] || area.default];
|
|
}
|
|
|
|
if (!visible && typeof visible !== "undefined") return null;
|
|
|
|
return (
|
|
<m.div ref={ref} className={classNames(gridClassName, className)} layout {...props}>
|
|
{children}
|
|
</m.div>
|
|
);
|
|
});
|