Skip to content

Commit

Permalink
feat: add bal widget navigate event
Browse files Browse the repository at this point in the history
  • Loading branch information
MaGOs92 committed Dec 5, 2024
1 parent 137781d commit e8e6531
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/contexts/BALWidget.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useCallback, useEffect, useRef, useState, createContext } from 'react'
import styled, { css } from 'styled-components'
import { matomoTrackEvent } from '@/lib/matomo'
import { env } from 'next-runtime-env'
import { useRouter } from 'next/navigation'

export const StyledIFrame = styled.iframe<{ $isOpen: boolean, $isVisible: boolean }>`
position: fixed;
Expand Down Expand Up @@ -52,6 +53,7 @@ interface BALWidgetProviderProps {

export function BALWidgetProvider({ children }: BALWidgetProviderProps) {
const balWidgetRef = useRef<HTMLIFrameElement>(null)
const router = useRouter()
const transitionTimeout = useRef<NodeJS.Timeout>()
const [isWidgetDisplayed, setIsWidgetDisplayed] = useState(false)
const [isWidgetVisible, setIsWidgetVisible] = useState(true)
Expand Down Expand Up @@ -158,6 +160,9 @@ export function BALWidgetProvider({ children }: BALWidgetProviderProps) {
case 'BAL_WIDGET_CONFIG_LOADED':
setIsBalWidgetConfigLoaded(true)
break
case 'BAL_WIDGET_PARENT_NAVIGATE_TO':
router.push(event.data.content)
break
default:
break
}
Expand All @@ -170,7 +175,7 @@ export function BALWidgetProvider({ children }: BALWidgetProviderProps) {
window.removeEventListener('message', BALWidgetMessageHandler)
clearTimeout(transitionTimeout.current)
}
}, [isBalWidgetOpen])
}, [isBalWidgetOpen, router])

return (
<BALWidgetContext.Provider value={{
Expand Down

0 comments on commit e8e6531

Please sign in to comment.