Skip to content

Commit 8fcbf2c

Browse files
authored
fix: Connect atoms not working inside iframe (calcom#25418)
* fix: google connect broken for iframe * chore: add changesets * chore: update atoms exports * chore: update atoms exports
1 parent a050ccb commit 8fcbf2c

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

.changeset/long-ties-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@calcom/atoms": patch
3+
---
4+
5+
This PR fixes the issue of connect atoms not working inside iframes. It also updates the atoms exports to include the `useAvailableSlots` hook.

packages/platform/atoms/hooks/connect/useConnect.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const useGetRedirectUrl = (
1818
redir?: string,
1919
isDryRun?: boolean
2020
) => {
21-
const redirectUrl = !!redir ? encodeURIComponent(redir) : "";
21+
const redirectUrl = redir ? encodeURIComponent(redir) : "";
2222

2323
const authUrl = useQuery({
2424
queryKey: getQueryKey(calendar),
@@ -49,7 +49,15 @@ export const useConnect = (calendar: (typeof CALENDARS)[number], redir?: string,
4949
const redirectUri = await refetch();
5050

5151
if (redirectUri.data) {
52-
window.location.href = redirectUri.data;
52+
let targetWindow;
53+
if (window !== window.top && window.top) {
54+
// if its an iframe, the target window should be the parent window
55+
targetWindow = window.top;
56+
} else {
57+
targetWindow = window;
58+
}
59+
60+
targetWindow.location.href = redirectUri.data;
5361
}
5462
};
5563

packages/platform/atoms/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ export { CreateSchedulePlatformWrapper as CreateSchedule } from "./create-schedu
4848
export { CreateScheduleForm } from "./create-schedule/CreateScheduleForm";
4949

5050
export { ListSchedulesPlatformWrapper as ListSchedules } from "./list-schedules/index";
51+
52+
export { useAvailableSlots } from "./hooks/useAvailableSlots";

0 commit comments

Comments
 (0)