diff --git a/global.d.ts b/global.d.ts index 7033e238..56fae289 100644 --- a/global.d.ts +++ b/global.d.ts @@ -2,10 +2,14 @@ declare global { interface Window { Analytics: unknown; DD_RUM: object | undefined; + DerivInterCom: { + initialize: (config: ICConfig) => void; + }; FreshChat: { initialize: (config: FreshChatConfig) => void; }; GrowthbookFeatures: { [key: string]: boolean }; + Intercom: ((action: IntercomAction) => void) | undefined; LC_API: { on_chat_ended: VoidFunction; open_chat_window: VoidFunction; @@ -23,6 +27,7 @@ declare global { }; fcWidget: { close: VoidFunction; + destroy: VoidFunction; hide: VoidFunction; isInitialized: () => boolean; isLoaded: () => boolean; @@ -31,6 +36,7 @@ declare global { setConfig: (config: Record>) => void; show: VoidFunction; user: { + clear: () => Promise; setLocale(locale: string): void; }; }; diff --git a/src/components/AppFooter/Livechat.tsx b/src/components/AppFooter/Livechat.tsx index 7541553e..dc8b9569 100644 --- a/src/components/AppFooter/Livechat.tsx +++ b/src/components/AppFooter/Livechat.tsx @@ -1,6 +1,5 @@ -import { useGrowthbookGetFeatureValue, useLiveChat } from '@/hooks/custom-hooks'; -import useFreshChat from '@/hooks/custom-hooks/useFreshchat'; -import Chat from '@/utils/chat'; +import { useFreshchat, useGrowthbookGetFeatureValue, useIntercom, useLiveChat } from '@/hooks/custom-hooks'; +import { Chat } from '@/utils'; import { LegacyLiveChatOutlineIcon } from '@deriv/quill-icons'; import { useTranslations } from '@deriv-com/translations'; import { Tooltip } from '@deriv-com/ui'; @@ -11,9 +10,13 @@ const Livechat = () => { const [isFreshChatEnabled, isGBLoaded] = useGrowthbookGetFeatureValue({ featureFlag: 'enable_freshworks_live_chat_p2p', }); + const [isIntercomEnabled] = useGrowthbookGetFeatureValue({ + featureFlag: 'enable_intercom_p2p', + }); const token = localStorage.getItem('authToken') || null; - const freshChat = useFreshChat(token); + const freshChat = useFreshchat(token, isFreshChatEnabled); + const icChat = useIntercom(token, isIntercomEnabled); setInterval(() => { /* This is for livechat last open state, @@ -23,7 +26,7 @@ const Livechat = () => { } }, 10); - if (!isGBLoaded || (isFreshChatEnabled && !freshChat?.isReady)) { + if (!isGBLoaded || (isFreshChatEnabled && !freshChat?.isReady) || (isIntercomEnabled && !icChat?.isReady)) { return null; } diff --git a/src/components/AppHeader/AppHeader.tsx b/src/components/AppHeader/AppHeader.tsx index 34ffe17f..96a39d8c 100644 --- a/src/components/AppHeader/AppHeader.tsx +++ b/src/components/AppHeader/AppHeader.tsx @@ -1,7 +1,7 @@ import { useEffect } from 'react'; import { getOauthUrl } from '@/constants'; import { api, useGrowthbookGetFeatureValue, useOAuth } from '@/hooks'; -import { getCurrentRoute } from '@/utils'; +import { Chat, getCurrentRoute } from '@/utils'; import { StandaloneCircleUserRegularIcon } from '@deriv/quill-icons'; import { useAuthData } from '@deriv-com/api-hooks'; import { useTranslations } from '@deriv-com/translations'; @@ -55,7 +55,14 @@ const AppHeader = () => { )} -