forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSIT-1539/Prince/Release PR/Freshchat Integration + Feature Flag togg…
…le (deriv-com#17196) * chore: fresh chat integration * fix: update script url * fix: update freshchat initialization * fix: show freshchat widget by default * fix: update useFreshChat hook * chore: loaded script from use-freshchat hook * fix: token undefined issue * fix: token issue for non-loggedin user * fix: remove temp auth * fix: chat ready issue, remove user when logged out * fix: update use freshchat hook * fix: point to freshchat js * fix: test temp js * fix: update freshchat hook * fix: update freshchat hook * fix: update locale config * fix: check fcwidget available * fix: update script and condition to check widget loaded * fix: update script * fix: remove language configs * fix: point to temp js * fix: freshchat url * chore: enable feature flag based on growthbook * chore: added query param flag enabler * fix: remove console * fix: close livechat widget when freshchat is enabled --------- Co-authored-by: Nuzhy-Deriv <[email protected]>
- Loading branch information
1 parent
047476e
commit 401990b
Showing
8 changed files
with
107 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/core/src/App/Components/Elements/LiveChat/use-freshchat.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useScript } from 'usehooks-ts'; | ||
|
||
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'; | ||
|
||
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); | ||
} | ||
} | ||
}; | ||
|
||
const initFreshChat = async () => { | ||
if (scriptStatus === 'ready' && window.FreshChat && window.fcSettings) { | ||
window.FreshChat.initialize({ | ||
token, | ||
hideButton: true, | ||
}); | ||
|
||
const intervalId = setInterval(() => checkFcWidget(intervalId), 500); | ||
|
||
return () => clearInterval(intervalId); | ||
} | ||
}; | ||
|
||
initFreshChat(); | ||
}, [isReady, language, scriptStatus, token]); | ||
|
||
return { | ||
isReady, | ||
widget: window.fcWidget, | ||
}; | ||
}; | ||
|
||
export default useFreshChat; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters