From 8fcbf2c167ce747e302c0c03095ddcdbebc728a3 Mon Sep 17 00:00:00 2001 From: Rajiv Sahal Date: Fri, 28 Nov 2025 20:14:20 +0530 Subject: [PATCH] fix: `Connect` atoms not working inside iframe (#25418) * fix: google connect broken for iframe * chore: add changesets * chore: update atoms exports * chore: update atoms exports --- .changeset/long-ties-obey.md | 5 +++++ packages/platform/atoms/hooks/connect/useConnect.ts | 12 ++++++++++-- packages/platform/atoms/index.ts | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changeset/long-ties-obey.md diff --git a/.changeset/long-ties-obey.md b/.changeset/long-ties-obey.md new file mode 100644 index 0000000000..1b18e82834 --- /dev/null +++ b/.changeset/long-ties-obey.md @@ -0,0 +1,5 @@ +--- +"@calcom/atoms": patch +--- + +This PR fixes the issue of connect atoms not working inside iframes. It also updates the atoms exports to include the `useAvailableSlots` hook. diff --git a/packages/platform/atoms/hooks/connect/useConnect.ts b/packages/platform/atoms/hooks/connect/useConnect.ts index bff70c92bd..88ad369a98 100644 --- a/packages/platform/atoms/hooks/connect/useConnect.ts +++ b/packages/platform/atoms/hooks/connect/useConnect.ts @@ -18,7 +18,7 @@ export const useGetRedirectUrl = ( redir?: string, isDryRun?: boolean ) => { - const redirectUrl = !!redir ? encodeURIComponent(redir) : ""; + const redirectUrl = redir ? encodeURIComponent(redir) : ""; const authUrl = useQuery({ queryKey: getQueryKey(calendar), @@ -49,7 +49,15 @@ export const useConnect = (calendar: (typeof CALENDARS)[number], redir?: string, const redirectUri = await refetch(); if (redirectUri.data) { - window.location.href = redirectUri.data; + let targetWindow; + if (window !== window.top && window.top) { + // if its an iframe, the target window should be the parent window + targetWindow = window.top; + } else { + targetWindow = window; + } + + targetWindow.location.href = redirectUri.data; } }; diff --git a/packages/platform/atoms/index.ts b/packages/platform/atoms/index.ts index 8131944872..d3e90ca3fc 100644 --- a/packages/platform/atoms/index.ts +++ b/packages/platform/atoms/index.ts @@ -48,3 +48,5 @@ export { CreateSchedulePlatformWrapper as CreateSchedule } from "./create-schedu export { CreateScheduleForm } from "./create-schedule/CreateScheduleForm"; export { ListSchedulesPlatformWrapper as ListSchedules } from "./list-schedules/index"; + +export { useAvailableSlots } from "./hooks/useAvailableSlots";