mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* 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: [email protected] <[email protected]> * 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: [email protected] <[email protected]> * 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: [email protected] <[email protected]> * 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 <[email protected]> Co-authored-by: Ryukemeister <[email protected]> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Benny Joo <[email protected]>
77 lines
2.4 KiB
TypeScript
77 lines
2.4 KiB
TypeScript
import { useEffect } from "react";
|
|
|
|
import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import classNames from "@calcom/ui/classNames";
|
|
import { Button } from "@calcom/ui/components/button";
|
|
import { Switch } from "@calcom/ui/components/form";
|
|
|
|
import { useOverlayCalendarStore } from "./store";
|
|
|
|
interface OverlayCalendarSwitchProps {
|
|
enabled?: boolean;
|
|
hasSession: boolean;
|
|
onStateChange: (state: boolean) => void;
|
|
}
|
|
|
|
export function OverlayCalendarSwitch({ enabled, hasSession, onStateChange }: OverlayCalendarSwitchProps) {
|
|
const { t } = useLocale();
|
|
const setContinueWithProvider = useOverlayCalendarStore((state) => state.setContinueWithProviderModal);
|
|
const setCalendarSettingsOverlay = useOverlayCalendarStore(
|
|
(state) => state.setCalendarSettingsOverlayModal
|
|
);
|
|
const layout = useBookerStoreContext((state) => state.layout);
|
|
const switchEnabled = enabled;
|
|
|
|
/**
|
|
* If a user is not logged in and the overlay calendar query param is true,
|
|
* show the continue modal so they can login / create an account
|
|
*/
|
|
useEffect(() => {
|
|
if (!hasSession && switchEnabled) {
|
|
onStateChange(false);
|
|
setContinueWithProvider(true);
|
|
}
|
|
}, [hasSession, switchEnabled, setContinueWithProvider, onStateChange]);
|
|
|
|
return (
|
|
<div
|
|
className={classNames(
|
|
"hidden gap-2",
|
|
layout === "week_view" || layout === "column_view" ? "xl:flex" : "md:flex"
|
|
)}>
|
|
<div className="flex items-center gap-2 pr-2">
|
|
<Switch
|
|
data-testid="overlay-calendar-switch"
|
|
checked={switchEnabled}
|
|
id="overlayCalendar"
|
|
onCheckedChange={(state) => {
|
|
if (!hasSession) {
|
|
setContinueWithProvider(state);
|
|
} else {
|
|
onStateChange(state);
|
|
}
|
|
}}
|
|
/>
|
|
<label
|
|
htmlFor="overlayCalendar"
|
|
className="text-emphasis text-sm font-medium leading-none hover:cursor-pointer">
|
|
{t("overlay_my_calendar")}
|
|
</label>
|
|
</div>
|
|
{hasSession && (
|
|
<Button
|
|
size="base"
|
|
data-testid="overlay-calendar-settings-button"
|
|
variant="icon"
|
|
color="secondary"
|
|
StartIcon="settings"
|
|
onClick={() => {
|
|
setCalendarSettingsOverlay(true);
|
|
}}
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|