-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
448f08e
commit b417721
Showing
1 changed file
with
38 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Button } from '@chakra-ui/react' | ||
import { useCallback, useEffect } from 'react' | ||
|
||
export const ChatwootButton: React.FC = () => { | ||
const chatWootEnabled = import.meta.env.VITE_FEATURE_CHATWOOT | ||
useEffect(() => { | ||
if (!chatWootEnabled) return // Add Chatwoot Settings | ||
;(window as any).chatwootSettings = { | ||
hideMessageBubble: true, | ||
position: 'left', // This can be left or right | ||
locale: 'en', // Language to be set | ||
type: 'standard', // [standard, expanded_bubble] | ||
} | ||
|
||
// Paste the script from inbox settings except the <script> tag | ||
;(function (d: Document) { | ||
const BASE_URL = import.meta.env.VITE_CHATWOOT_URL | ||
const g = d.createElement('script') | ||
const s = d.getElementsByTagName('script')[0] | ||
g.src = BASE_URL + '/packs/js/sdk.js' | ||
s.parentNode?.insertBefore(g, s) | ||
g.async = true | ||
g.onload = function () { | ||
;(window as any).chatwootSDK.run({ | ||
websiteToken: import.meta.env.VITE_CHATWOOT_TOKEN, | ||
baseUrl: BASE_URL, | ||
}) | ||
} | ||
})(document) | ||
}, [chatWootEnabled]) | ||
|
||
const handleChatWoot = useCallback(() => { | ||
// @ts-ignore | ||
if (window.$chatwoot) window.$chatwoot.toggle() | ||
}, []) | ||
|
||
return chatWootEnabled ? <Button onClick={handleChatWoot}>Get support</Button> : null | ||
} |