File tree Expand file tree Collapse file tree 3 files changed +40
-6
lines changed
Expand file tree Collapse file tree 3 files changed +40
-6
lines changed Original file line number Diff line number Diff line change 1+ import { useEffect } from 'react' ;
2+
3+ const INTERCOM_BUTTON_SELECTOR = `div[aria-label="Open Intercom Messenger"]` ;
4+ const INTERCOM_IFRAME_SELECTOR = `iframe[name="intercom-launcher-frame"]` ;
5+
6+ export const useHideIntercom = ( ) => {
7+ useEffect ( ( ) => {
8+ const intercomButton = document . querySelector ( INTERCOM_BUTTON_SELECTOR ) ;
9+ const intercomIframe = document . querySelector ( INTERCOM_IFRAME_SELECTOR ) ;
10+
11+ const originalButtonDisplay = intercomButton ? ( intercomButton as HTMLElement ) . style . display : '' ;
12+ const originalIframeDisplay = intercomIframe ? ( intercomIframe as HTMLElement ) . style . display : '' ;
13+
14+ const hideIntercom = ( ) => {
15+ if ( intercomButton ) {
16+ ( intercomButton as HTMLElement ) . style . display = 'none' ;
17+ }
18+ if ( intercomIframe ) {
19+ ( intercomIframe as HTMLElement ) . style . display = 'none' ;
20+ }
21+ } ;
22+
23+ const showIntercom = ( ) => {
24+ if ( intercomButton ) {
25+ ( intercomButton as HTMLElement ) . style . display = originalButtonDisplay || 'block' ;
26+ }
27+ if ( intercomIframe ) {
28+ ( intercomIframe as HTMLElement ) . style . display = originalIframeDisplay || 'inline' ;
29+ }
30+ } ;
31+
32+ hideIntercom ( ) ;
33+
34+ return ( ) => {
35+ showIntercom ( ) ;
36+ } ;
37+ } , [ ] ) ;
38+ } ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { BotPage } from "./index";
22import { RouteComponentProps } from "react-router" ;
33import { AlertSnackbarProvider } from "@postgres.ai/shared/components/AlertSnackbar/useAlertSnackbar" ;
44import { AiBotProvider } from "./hooks" ;
5+ import { useHideIntercom } from "../../hooks/useHideIntercom" ;
56
67export interface BotWrapperProps {
78 envData : {
@@ -24,6 +25,7 @@ export interface BotWrapperProps {
2425
2526
2627export const BotWrapper = ( props : BotWrapperProps ) => {
28+ useHideIntercom ( ) ;
2729 return (
2830 < AlertSnackbarProvider >
2931 < AiBotProvider args = { { threadId : props . match . params . threadId , orgId : props . orgData . id } } >
Original file line number Diff line number Diff line change @@ -194,11 +194,6 @@ export const Command = React.memo((props: Props) => {
194194 setValue ( '' )
195195 } , [ threadId ] ) ;
196196
197- // Floating intercom.
198- const sendButtonRef = useRef < HTMLButtonElement | null > ( null )
199-
200- useFloatingIntercom ( sendButtonRef )
201-
202197 return (
203198 < div className = { classes . root } >
204199 < TextField
@@ -222,7 +217,6 @@ export const Command = React.memo((props: Props) => {
222217 onClick = { triggerSend }
223218 className = { classes . iconButton }
224219 disabled = { sendDisabled || value . length === 0 }
225- ref = { sendButtonRef }
226220 >
227221 < SendRoundedIcon />
228222 </ IconButton >
You can’t perform that action at this time.
0 commit comments