-
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.
Merge pull request #7 from eduzz/feature-ct2-726
Hyperflow on topbar
- Loading branch information
Showing
7 changed files
with
132 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import useExternalScript from './import'; | ||
|
||
type HyperflowParams = { | ||
id?: number; | ||
name?: string; | ||
email?: string; | ||
eliteChatToken?: string; | ||
original_id?: number; | ||
original_name?: string; | ||
original_email?: string; | ||
sender?: string; | ||
}; | ||
|
||
interface SupportChatProps { | ||
jwtToHyperflow: string; | ||
currentUser: any; | ||
hyperflowConfig: any; | ||
} | ||
|
||
function getChatTokenID(currentUser: any, hyperflowConfig: any) { | ||
const chatUnityID = hyperflowConfig.chatUnityID; | ||
const chatBlackID = hyperflowConfig.chatBlackID; | ||
const chatEliteID = hyperflowConfig.chatEliteID; | ||
const beltsCanViewChatBlack = ['Black', 'Golden', 'Sensei']; | ||
const beltUserCanViewChatBlack = beltsCanViewChatBlack.includes((currentUser?.belt || '').split(' ')[0]); | ||
|
||
if (currentUser?.tag === 'unity') return chatUnityID; | ||
if (beltUserCanViewChatBlack || currentUser?.isClubeBlack) return chatBlackID; | ||
return chatEliteID; | ||
} | ||
|
||
const HyperflowSupportChat: React.FC<SupportChatProps> = ({ jwtToHyperflow, currentUser, hyperflowConfig }) => { | ||
const hyperflow = useExternalScript('https://webchat.hyperflow.global/sdk.js'); | ||
const chatToken = getChatTokenID(currentUser, hyperflowConfig); | ||
|
||
if (hyperflow === 'ready') { | ||
Hyperflow.init(chatToken).on('getStarted', () => { | ||
const params: HyperflowParams = { | ||
id: currentUser?.id, | ||
name: currentUser?.name.split(' ')[0], | ||
email: currentUser?.email, | ||
sender: jwtToHyperflow | ||
}; | ||
|
||
if (currentUser?.isAccessPolicy) { | ||
params.original_id = currentUser?.originalUserId; | ||
params.original_name = currentUser?.originalUserName?.split(' ')[0]; | ||
params.original_email = currentUser?.originalUserEmail; | ||
} | ||
|
||
Hyperflow.initFlow(hyperflowConfig.flowId, params); | ||
}); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
export default HyperflowSupportChat; |
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'; | ||
|
||
const useExternalScript = url => { | ||
const [state, setState] = useState(url ? 'loading' : 'idle'); | ||
|
||
useEffect(() => { | ||
if (!url) { | ||
setState('idle'); | ||
return; | ||
} | ||
|
||
let script = document.querySelector(`script[src="${url}"]`); | ||
|
||
const handleScript = e => { | ||
setState(e.type === 'load' ? 'ready' : 'error'); | ||
}; | ||
|
||
if (!script) { | ||
script = document.createElement('script'); | ||
script.type = 'application/javascript'; | ||
script.src = url; | ||
script.async = true; | ||
document.body.appendChild(script); | ||
} | ||
|
||
script.addEventListener('load', handleScript); | ||
script.addEventListener('error', handleScript); | ||
|
||
return () => { | ||
script.removeEventListener('load', handleScript); | ||
script.removeEventListener('error', handleScript); | ||
}; | ||
}, [url]); | ||
|
||
return state; | ||
}; | ||
|
||
export default useExternalScript; |
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,21 @@ | ||
import HyperflowSupportChat from './chat'; | ||
|
||
export interface TopbarHyperflowSupportChatProps { | ||
jwtToHyperflow?: string; | ||
currentUser?: any; | ||
hyperflowConfig?: any; | ||
} | ||
|
||
const TopbarHyperflowSupportChat = ({ | ||
jwtToHyperflow, | ||
currentUser, | ||
hyperflowConfig | ||
}: TopbarHyperflowSupportChatProps) => { | ||
if (!jwtToHyperflow) return null; | ||
|
||
return ( | ||
<HyperflowSupportChat jwtToHyperflow={jwtToHyperflow} currentUser={currentUser} hyperflowConfig={hyperflowConfig} /> | ||
); | ||
}; | ||
|
||
export default TopbarHyperflowSupportChat; |
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,6 +1,6 @@ | ||
{ | ||
"name": "@eduzz/ui-layout", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"keywords": [ | ||
"eduzz", | ||
"react", | ||
|