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" ;
55import { IntercomProvider } from "react-use-intercom" ;
66
77import { 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
0 commit comments