fix: Intercom not opening with openSupport param (#23755)
* fix: Intercom not opening with openSupport param * remove logs * remove unused
This commit is contained in:
@@ -37,6 +37,7 @@ export const IntercomContactForm = () => {
|
||||
setShowTrigger(showTrigger);
|
||||
},
|
||||
};
|
||||
window.dispatchEvent(new Event("support:ready"));
|
||||
}
|
||||
|
||||
return () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useEffect, type FC } from "react";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useEffect, useState, type FC } from "react";
|
||||
import { IntercomProvider } from "react-use-intercom";
|
||||
|
||||
import { useBootIntercom } from "@calcom/ee/support/lib/intercom/useIntercom";
|
||||
@@ -28,14 +28,40 @@ const Provider: FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const { hasPaidPlan } = useHasPaidPlan();
|
||||
const isMobile = useMediaQuery("(max-width: 768px)");
|
||||
const flagMap = useFlagMap();
|
||||
const searchParams = useSearchParams();
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
|
||||
const shouldOpenSupport =
|
||||
pathname === "/event-types" && (searchParams?.has("openPlain") || searchParams?.has("openSupport"));
|
||||
|
||||
useEffect(() => {
|
||||
const handleSupportReady = () => {
|
||||
if (window.Support) {
|
||||
window.Support.shouldShowTriggerButton?.(!isMobile);
|
||||
|
||||
if (shouldOpenSupport) {
|
||||
window.Support.open();
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.delete("openPlain");
|
||||
url.searchParams.delete("openSupport");
|
||||
router.replace(url.pathname + url.search);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (window.Support) {
|
||||
window.Support.shouldShowTriggerButton(!isMobile);
|
||||
handleSupportReady();
|
||||
} else {
|
||||
window.addEventListener("support:ready", handleSupportReady);
|
||||
}
|
||||
}, [isMobile]);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("support:ready", handleSupportReady);
|
||||
};
|
||||
//eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [shouldOpenSupport, isMobile]);
|
||||
|
||||
const pathname = usePathname();
|
||||
const isOnboardingPage = pathname?.startsWith("/getting-started");
|
||||
const isCalVideoPage = pathname?.startsWith("/video/");
|
||||
|
||||
|
||||
@@ -179,6 +179,7 @@ export const useBootIntercom = () => {
|
||||
});
|
||||
},
|
||||
};
|
||||
window.dispatchEvent(new Event("support:ready"));
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [user, statsData, hasPaidPlan, isTieredSupportEnabled]);
|
||||
|
||||
Reference in New Issue
Block a user