|
|
|
@ -1,4 +1,10 @@ |
|
|
|
import { ReactNode, useEffect } from 'react' |
|
|
|
import { |
|
|
|
|
|
|
|
ReactNode, |
|
|
|
|
|
|
|
useEffect, |
|
|
|
|
|
|
|
useState, |
|
|
|
|
|
|
|
} from 'react' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { useLocation } from 'react-router' |
|
|
|
|
|
|
|
|
|
|
|
import { useMatomo } from '@jonkoops/matomo-tracker-react' |
|
|
|
import { useMatomo } from '@jonkoops/matomo-tracker-react' |
|
|
|
|
|
|
|
|
|
|
|
@ -6,7 +12,10 @@ import { getLanguageUrlParam } from 'helpers/languageUrlParam' |
|
|
|
|
|
|
|
|
|
|
|
import { AuthStore } from 'features/AuthStore' |
|
|
|
import { AuthStore } from 'features/AuthStore' |
|
|
|
import { LexicsStore } from 'features/LexicsStore' |
|
|
|
import { LexicsStore } from 'features/LexicsStore' |
|
|
|
import { useLocation } from 'react-router' |
|
|
|
|
|
|
|
|
|
|
|
import { getGeoInfo } from 'requests' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { redirectToUrl } from 'helpers' |
|
|
|
|
|
|
|
|
|
|
|
const initialLanguage = getLanguageUrlParam() |
|
|
|
const initialLanguage = getLanguageUrlParam() |
|
|
|
|
|
|
|
|
|
|
|
@ -17,6 +26,7 @@ type Props = { |
|
|
|
export const GlobalStores = ({ children }: Props) => { |
|
|
|
export const GlobalStores = ({ children }: Props) => { |
|
|
|
const { pathname, search } = useLocation() |
|
|
|
const { pathname, search } = useLocation() |
|
|
|
const { trackPageView } = useMatomo() |
|
|
|
const { trackPageView } = useMatomo() |
|
|
|
|
|
|
|
const [isGeoReady, setIsGeoReady] = useState(false) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
const isProduction = process.env.REACT_APP_ENV === 'production' |
|
|
|
const isProduction = process.env.REACT_APP_ENV === 'production' |
|
|
|
@ -24,6 +34,23 @@ export const GlobalStores = ({ children }: Props) => { |
|
|
|
if (isProduction) trackPageView() |
|
|
|
if (isProduction) trackPageView() |
|
|
|
}, [trackPageView, pathname, search]) |
|
|
|
}, [trackPageView, pathname, search]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
(async () => { |
|
|
|
|
|
|
|
if (pathname === '/' && search === '') { |
|
|
|
|
|
|
|
const geo = await getGeoInfo() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (geo.country_code === 'TN') { |
|
|
|
|
|
|
|
redirectToUrl('https://diwan.insports.tv') |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
setIsGeoReady(true) |
|
|
|
|
|
|
|
})() |
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isGeoReady) return null |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<LexicsStore initialLanguage={initialLanguage}> |
|
|
|
<LexicsStore initialLanguage={initialLanguage}> |
|
|
|
<AuthStore> |
|
|
|
<AuthStore> |
|
|
|
|