Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): Hotfix - Boost chat panel, use pushUp prop #17271 #17272

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading