Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Changes to fix exception with zendesk not defined (#10974)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzlamateen authored Aug 16, 2024
1 parent 13ad7d1 commit 983bcfc
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/client-core/src/hooks/useZendesk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { AuthState } from '../user/services/AuthService'

declare global {
interface Window {
zE: (...args: any) => void
zE?: (...args: any) => void
}
}

Expand All @@ -49,7 +49,7 @@ export const useZendesk = () => {
const authenticateUser = () => {
if (authenticated.value || config.client.zendesk.authenticationEnabled !== 'true') return

window.zE('messenger', 'loginUser', function (callback: any) {
window.zE?.('messenger', 'loginUser', function (callback: any) {
zendeskMutation.create().then(async (token) => {
authenticated.set(true)
await callback(token)
Expand All @@ -71,10 +71,10 @@ export const useZendesk = () => {
hideWidget()
authenticateUser()
}
window.zE('messenger:on', 'close', () => {
window.zE?.('messenger:on', 'close', () => {
hideWidget()
})
window.zE('messenger:on', 'open', function () {
window.zE?.('messenger:on', 'open', function () {
showWidget()
})
})
Expand All @@ -89,28 +89,28 @@ export const useZendesk = () => {
authenticateUser()
} else if (user.isGuest.value && initialized.value) {
closeChat()
window.zE('messenger', 'logoutUser')
window.zE?.('messenger', 'logoutUser')
}
}, [user.value])

const hideWidget = () => {
if (!initialized.value) return
window.zE('messenger', 'hide')
window.zE?.('messenger', 'hide')
isWidgetVisible.set(false)
}
const showWidget = () => {
if (!initialized.value) return
window.zE('messenger', 'show')
window.zE?.('messenger', 'show')
isWidgetVisible.set(true)
}
const openChat = () => {
if (!initialized.value) return
window.zE('messenger', 'open')
window.zE?.('messenger', 'open')
}

const closeChat = () => {
if (!initialized.value) return
window.zE('messenger', 'close')
window.zE?.('messenger', 'close')
}

return {
Expand Down

0 comments on commit 983bcfc

Please sign in to comment.