diff --git a/packages/platform/atoms/booker/BookerPlatformWrapper.tsx b/packages/platform/atoms/booker/BookerPlatformWrapper.tsx index a2afb0acb2..d3299715f7 100644 --- a/packages/platform/atoms/booker/BookerPlatformWrapper.tsx +++ b/packages/platform/atoms/booker/BookerPlatformWrapper.tsx @@ -4,6 +4,7 @@ import { shallow } from "zustand/shallow"; import dayjs from "@calcom/dayjs"; import type { BookerProps } from "@calcom/features/bookings/Booker"; import { Booker as BookerComponent } from "@calcom/features/bookings/Booker"; +import { useOverlayCalendarStore } from "@calcom/features/bookings/Booker/components/OverlayCalendar/store"; import { useBookerLayout } from "@calcom/features/bookings/Booker/components/hooks/useBookerLayout"; import { useBookingForm } from "@calcom/features/bookings/Booker/components/hooks/useBookingForm"; import { useLocalSet } from "@calcom/features/bookings/Booker/components/hooks/useLocalSet"; @@ -179,8 +180,14 @@ export const BookerPlatformWrapper = (props: BookerPlatformWrapperAtomProps) => }); const slots = useSlots(event); - const { data: connectedCalendars, isPending: fetchingConnectedCalendars } = useConnectedCalendars(); - const calendars = connectedCalendars as ApiSuccessResponse; + const [calendarSettingsOverlay] = useOverlayCalendarStore( + (state) => [state.calendarSettingsOverlayModal, state.setCalendarSettingsOverlayModal], + shallow + ); + const { data: connectedCalendars, isPending: fetchingConnectedCalendars } = useConnectedCalendars({ + enabled: !!calendarSettingsOverlay, + }); + const calendars = connectedCalendars as ConnectedDestinationCalendars; const { set, clearSet } = useLocalSet<{ credentialId: number; @@ -267,7 +274,7 @@ export const BookerPlatformWrapper = (props: BookerPlatformWrapperAtomProps) => calendars={{ overlayBusyDates: overlayBusyDates?.data, isOverlayCalendarEnabled: false, - connectedCalendars: calendars?.data.connectedCalendars || [], + connectedCalendars: calendars?.connectedCalendars || [], loadingConnectedCalendar: fetchingConnectedCalendars, onToggleCalendar: () => { return; diff --git a/packages/platform/atoms/hooks/useConnectedCalendars.tsx b/packages/platform/atoms/hooks/useConnectedCalendars.tsx index 01eda5256e..48e436f218 100644 --- a/packages/platform/atoms/hooks/useConnectedCalendars.tsx +++ b/packages/platform/atoms/hooks/useConnectedCalendars.tsx @@ -1,7 +1,5 @@ import { useQuery } from "@tanstack/react-query"; -import { shallow } from "zustand/shallow"; -import { useOverlayCalendarStore } from "@calcom/features/bookings/Booker/components/OverlayCalendar/store"; import { SUCCESS_STATUS } from "@calcom/platform-constants"; import type { ConnectedDestinationCalendars } from "@calcom/platform-libraries"; import type { ApiResponse } from "@calcom/platform-types"; @@ -9,22 +7,18 @@ import type { ApiResponse } from "@calcom/platform-types"; import http from "../lib/http"; export const QUERY_KEY = "get-connected-calendars"; -export const useConnectedCalendars = () => { - const [calendarSettingsOverlay] = useOverlayCalendarStore( - (state) => [state.calendarSettingsOverlayModal, state.setCalendarSettingsOverlayModal], - shallow - ); +export const useConnectedCalendars = (props: { enabled?: boolean }) => { const calendars = useQuery({ queryKey: [QUERY_KEY], queryFn: () => { return http.get>("/ee/calendars").then((res) => { if (res.data.status === SUCCESS_STATUS) { - return res.data; + return res.data?.data; } throw new Error(res.data.error.message); }); }, - enabled: !!calendarSettingsOverlay, + enabled: props?.enabled ?? true, }); return calendars; diff --git a/packages/platform/atoms/index.ts b/packages/platform/atoms/index.ts index 3ecabb3cdf..db27ccd37b 100644 --- a/packages/platform/atoms/index.ts +++ b/packages/platform/atoms/index.ts @@ -4,3 +4,4 @@ export { PlatformAvailabilitySettingsWrapper as AvailabilitySettings } from "./a export { BookerPlatformWrapper as Booker } from "./booker"; export { useIsPlatform } from "./hooks/useIsPlatform"; export { useAtomsContext } from "./hooks/useAtomsContext"; +export { useConnectedCalendars } from "./hooks/useConnectedCalendars"; diff --git a/packages/platform/examples/base/src/pages/calendars.tsx b/packages/platform/examples/base/src/pages/calendars.tsx index f5fc83c5e9..d8452ceda7 100644 --- a/packages/platform/examples/base/src/pages/calendars.tsx +++ b/packages/platform/examples/base/src/pages/calendars.tsx @@ -1,14 +1,41 @@ import { Navbar } from "@/components/Navbar"; import { Inter } from "next/font/google"; +import { useConnectedCalendars } from "@calcom/atoms"; + const inter = Inter({ subsets: ["latin"] }); export default function Calendars(props: { calUsername: string; calEmail: string }) { + const { isLoading, data: calendars } = useConnectedCalendars(); + const connectedCalendars = calendars?.connectedCalendars ?? []; + const destinationCalendar = calendars?.destinationCalendar ?? {}; return (
-
-

This is the google calendar page

+
+

Your Connected Calendars

+ {isLoading ? ( +
Loading...
+ ) : ( + Boolean(connectedCalendars?.length) && + connectedCalendars.map((connectedCalendar) => ( +
+

{connectedCalendar.integration.name}

+ {connectedCalendar.calendars.map((calendar) => ( +
+

{calendar.name}

+
+ ))} +
+ )) + )} +
+ {!isLoading && destinationCalendar.id && ( +
+

Destination Calendar: {destinationCalendar.name}

+

{destinationCalendar.integrationTitle}

+
+ )}
);