-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #413 from Nuzhy-Deriv/nuzhy/intercom-integration
nuzhy/CSIT-1704/intercom integration
- Loading branch information
Showing
18 changed files
with
147 additions
and
47 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
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
2 changes: 1 addition & 1 deletion
2
src/components/Modals/AdErrorTooltipModal/AdErrorTooltipModal.tsx
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
2 changes: 1 addition & 1 deletion
2
src/components/Modals/AdVisibilityErrorModal/AdVisibilityErrorModal.tsx
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
2 changes: 1 addition & 1 deletion
2
src/components/Modals/AdVisibilityErrorModal/__tests__/AdVisibilityErrorModal.spec.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +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/v1.0.2.js'); | ||
const useFreshChat = (token: string | null, flag: boolean) => { | ||
const freshchatScript = 'https://static.deriv.com/scripts/freshchat/v1.0.2.js'; | ||
const scriptStatus = useScript(flag ? freshchatScript : null); | ||
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) { | ||
if (!flag || scriptStatus !== 'ready' || !window.FreshChat || !window.fcSettings) { | ||
return; | ||
} | ||
|
||
let checkInterval: NodeJS.Timeout; | ||
|
||
const initializeFreshChat = () => { | ||
window.FreshChat.initialize({ | ||
hideButton: true, | ||
token, | ||
}); | ||
|
||
checkInterval = setInterval(() => { | ||
if (window?.fcWidget?.isInitialized()) { | ||
setIsReady(true); | ||
clearInterval(intervalId); | ||
clearInterval(checkInterval); | ||
} | ||
} | ||
}, 500); | ||
}; | ||
|
||
const initFreshChat = async () => { | ||
if (scriptStatus === 'ready' && window.FreshChat && window.fcSettings) { | ||
window.FreshChat.initialize({ | ||
hideButton: true, | ||
token, | ||
}); | ||
|
||
const intervalId: NodeJS.Timeout = setInterval(() => checkFcWidget(intervalId), 500); | ||
initializeFreshChat(); | ||
|
||
return () => clearInterval(intervalId); | ||
return () => { | ||
if (checkInterval) { | ||
clearInterval(checkInterval); | ||
} | ||
}; | ||
}, [flag, scriptStatus, token]); | ||
|
||
initFreshChat(); | ||
}, [isReady, language, scriptStatus, token]); | ||
|
||
return { | ||
isReady, | ||
widget: window.fcWidget, | ||
}; | ||
return { isReady }; | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useScript } from 'usehooks-ts'; | ||
|
||
const useIntercom = (token: string | null, flag: boolean) => { | ||
const intercomScript = 'https://static.deriv.com/scripts/intercom/v1.0.1.js'; | ||
const scriptStatus = useScript(flag ? intercomScript : null); | ||
const [isReady, setIsReady] = useState(false); | ||
|
||
useEffect(() => { | ||
if (!flag || scriptStatus !== 'ready' || !window?.DerivInterCom) return; | ||
|
||
let intervalId: NodeJS.Timeout; | ||
|
||
const initIntercom = () => { | ||
window.DerivInterCom.initialize({ | ||
hideLauncher: true, | ||
token, | ||
}); | ||
|
||
intervalId = setInterval(() => { | ||
if (window?.Intercom && !isReady) { | ||
setIsReady(true); | ||
clearInterval(intervalId); | ||
} | ||
}, 500); | ||
}; | ||
|
||
initIntercom(); | ||
|
||
return () => { | ||
if (intervalId) clearInterval(intervalId); | ||
}; | ||
}, [flag, isReady, scriptStatus, token]); | ||
|
||
return { isReady }; | ||
}; | ||
|
||
export default useIntercom; |
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