Skip to content

Commit a55d56f

Browse files
authored
fix: Intercom not opening with openSupport param (calcom#23755)
* fix: Intercom not opening with openSupport param * remove logs * remove unused
1 parent 1d25265 commit a55d56f

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

packages/features/ee/support/components/IntercomContactForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const IntercomContactForm = () => {
3737
setShowTrigger(showTrigger);
3838
},
3939
};
40+
window.dispatchEvent(new Event("support:ready"));
4041
}
4142

4243
return () => {

packages/features/ee/support/lib/intercom/provider.tsx

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

3-
import { usePathname } from "next/navigation";
4-
import { useEffect, type FC } from "react";
3+
import { usePathname, useRouter, useSearchParams } from "next/navigation";
4+
import { useEffect, useState, type FC } from "react";
55
import { IntercomProvider } from "react-use-intercom";
66

77
import { useBootIntercom } from "@calcom/ee/support/lib/intercom/useIntercom";
@@ -28,14 +28,40 @@ const Provider: FC<{ children: React.ReactNode }> = ({ children }) => {
2828
const { hasPaidPlan } = useHasPaidPlan();
2929
const isMobile = useMediaQuery("(max-width: 768px)");
3030
const flagMap = useFlagMap();
31+
const searchParams = useSearchParams();
32+
const pathname = usePathname();
33+
const router = useRouter();
34+
35+
const shouldOpenSupport =
36+
pathname === "/event-types" && (searchParams?.has("openPlain") || searchParams?.has("openSupport"));
3137

3238
useEffect(() => {
39+
const handleSupportReady = () => {
40+
if (window.Support) {
41+
window.Support.shouldShowTriggerButton?.(!isMobile);
42+
43+
if (shouldOpenSupport) {
44+
window.Support.open();
45+
const url = new URL(window.location.href);
46+
url.searchParams.delete("openPlain");
47+
url.searchParams.delete("openSupport");
48+
router.replace(url.pathname + url.search);
49+
}
50+
}
51+
};
52+
3353
if (window.Support) {
34-
window.Support.shouldShowTriggerButton(!isMobile);
54+
handleSupportReady();
55+
} else {
56+
window.addEventListener("support:ready", handleSupportReady);
3557
}
36-
}, [isMobile]);
3758

38-
const pathname = usePathname();
59+
return () => {
60+
window.removeEventListener("support:ready", handleSupportReady);
61+
};
62+
//eslint-disable-next-line react-hooks/exhaustive-deps
63+
}, [shouldOpenSupport, isMobile]);
64+
3965
const isOnboardingPage = pathname?.startsWith("/getting-started");
4066
const isCalVideoPage = pathname?.startsWith("/video/");
4167

packages/features/ee/support/lib/intercom/useIntercom.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export const useBootIntercom = () => {
179179
});
180180
},
181181
};
182+
window.dispatchEvent(new Event("support:ready"));
182183
}
183184
// eslint-disable-next-line react-hooks/exhaustive-deps
184185
}, [user, statsData, hasPaidPlan, isTieredSupportEnabled]);

0 commit comments

Comments
 (0)