Skip to content

Commit

Permalink
Nuzhy/_/initiate freschat when feature tag enabled (deriv-com#17247)
Browse files Browse the repository at this point in the history
* fix: initiate freschat when feature tag enabled

* fix: isGBloaded condition added
  • Loading branch information
Nuzhy-Deriv authored Oct 30, 2024
1 parent d8cd112 commit cbd9d49
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { useEffect, useState } from 'react';
import { useScript } from 'usehooks-ts';
import { useGrowthbookGetFeatureValue } from '@deriv/hooks';

const useFreshChat = (token: string | null) => {
const scriptStatus = useScript('https://static.deriv.com/scripts/freshchat.js');
const [isReady, setIsReady] = useState(false);
const language = localStorage.getItem('i18n_language') || 'EN';
const [enable_freshworks_live_chat, isGBLoaded] = useGrowthbookGetFeatureValue({
featureFlag: 'enable_freshworks_live_chat',
});

useEffect(() => {
const checkFcWidget = (intervalId: NodeJS.Timeout) => {
if (typeof window !== 'undefined') {
if (window.fcWidget?.isInitialized() == true && !isReady) {
// window.fcWidget?.user.setLocale(language.toLowerCase());
setIsReady(true);
clearInterval(intervalId);
}
Expand All @@ -30,8 +32,8 @@ const useFreshChat = (token: string | null) => {
}
};

initFreshChat();
}, [isReady, language, scriptStatus, token]);
enable_freshworks_live_chat && isGBLoaded && initFreshChat();
}, [enable_freshworks_live_chat, isGBLoaded, isReady, scriptStatus, token]);

return {
isReady,
Expand Down

0 comments on commit cbd9d49

Please sign in to comment.