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 "@calcom/features/bookings/Booker/components/OverlayCalendar/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 (
{ if (!hasSession) { setContinueWithProvider(state); } else { onStateChange(state); } }} />
{hasSession && (
); }