File tree 3 files changed +40
-6
lines changed
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";
2
2
import { RouteComponentProps } from "react-router" ;
3
3
import { AlertSnackbarProvider } from "@postgres.ai/shared/components/AlertSnackbar/useAlertSnackbar" ;
4
4
import { AiBotProvider } from "./hooks" ;
5
+ import { useHideIntercom } from "../../hooks/useHideIntercom" ;
5
6
6
7
export interface BotWrapperProps {
7
8
envData : {
@@ -24,6 +25,7 @@ export interface BotWrapperProps {
24
25
25
26
26
27
export const BotWrapper = ( props : BotWrapperProps ) => {
28
+ useHideIntercom ( ) ;
27
29
return (
28
30
< AlertSnackbarProvider >
29
31
< 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) => {
194
194
setValue ( '' )
195
195
} , [ threadId ] ) ;
196
196
197
- // Floating intercom.
198
- const sendButtonRef = useRef < HTMLButtonElement | null > ( null )
199
-
200
- useFloatingIntercom ( sendButtonRef )
201
-
202
197
return (
203
198
< div className = { classes . root } >
204
199
< TextField
@@ -222,7 +217,6 @@ export const Command = React.memo((props: Props) => {
222
217
onClick = { triggerSend }
223
218
className = { classes . iconButton }
224
219
disabled = { sendDisabled || value . length === 0 }
225
- ref = { sendButtonRef }
226
220
>
227
221
< SendRoundedIcon />
228
222
</ IconButton >
You can’t perform that action at this time.
0 commit comments