Skip to content

Commit

Permalink
fix(web): Hotfix - Boost chat panel, use pushUp prop #17271 (#17272)
Browse files Browse the repository at this point in the history
* Push chat panel up

* Add translation to text in chat bubble

* Open chat if query params are present
  • Loading branch information
RunarVestmann authored Dec 18, 2024
1 parent 5dff2c6 commit ad91967
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import React, { useEffect, useState } from 'react'
import { config, boostChatPanelEndpoints } from './config'
import React, { useEffect, useMemo, useState } from 'react'
import { useQuery } from '@apollo/client'

import { Query, QueryGetNamespaceArgs } from '@island.is/web/graphql/schema'
import { useNamespaceStrict } from '@island.is/web/hooks'
import { useI18n } from '@island.is/web/i18n'
import { GET_NAMESPACE_QUERY } from '@island.is/web/screens/queries'

import { ChatBubble } from '../ChatBubble'
import { BoostChatPanelProps } from '../types'
import { boostChatPanelEndpoints, config } from './config'

declare global {
interface Window {
Expand All @@ -16,6 +23,7 @@ export const BoostChatPanel: React.FC<
React.PropsWithChildren<BoostChatPanelProps>
> = ({ endpoint, pushUp = false }) => {
const [showButton, setShowButton] = useState(Boolean(window.boost)) // we show button when chat already loaded
const { activeLocale } = useI18n()

useEffect(() => {
// recreate the chat panel if we are on a different endpoint
Expand Down Expand Up @@ -60,19 +68,43 @@ export const BoostChatPanel: React.FC<
)

setShowButton(true)

const queryParam = new URLSearchParams(window.location.search).get(
'wa_lid',
)
if (queryParam && ['t10', 't11'].includes(queryParam)) {
window.boost.chatPanel.show()
}
})

el.src = boostChatPanelEndpoints[endpoint].url
el.id = 'boost-script'
document.body.appendChild(el)
}
}, [])
}, [endpoint])

const { data } = useQuery<Query, QueryGetNamespaceArgs>(GET_NAMESPACE_QUERY, {
variables: {
input: {
lang: activeLocale,
namespace: 'ChatPanels',
},
},
})

const namespace = useMemo(
() => JSON.parse(data?.getNamespace?.fields || '{}'),
[data?.getNamespace?.fields],
)

const n = useNamespaceStrict(namespace)

return (
<ChatBubble
text={'Hæ, get ég aðstoðað?'}
text={n('chatBubbleText', 'Hæ, get ég aðstoðað?')}
onClick={() => window.boost.chatPanel.show()}
isVisible={showButton}
pushUp={pushUp}
/>
)
}
Expand Down

0 comments on commit ad91967

Please sign in to comment.