fix(#188): check geo, redirect to diwan

pull/49/head
Rakov Roman 3 years ago
parent 5b9130eb11
commit 9a6d3cae1b
  1. 31
      src/features/GlobalStores/index.tsx
  2. 20
      src/requests/getGeoInfo.tsx
  3. 1
      src/requests/index.tsx

@ -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>

@ -0,0 +1,20 @@
import { AUTH_SERVICE } from 'config'
import { callApi } from 'helpers'
export type GeoInfoType = {
city: string,
country_code: string,
time_zone: string,
}
export const getGeoInfo = async (): Promise<GeoInfoType> => {
const config = {
method: 'GET',
}
return callApi({
config,
url: `${AUTH_SERVICE}/geoinfo`,
})
}

@ -25,4 +25,5 @@ export * from './getPlayerPlaylists'
export * from './getSubscriptions' export * from './getSubscriptions'
export * from './buySubscription' export * from './buySubscription'
export * from './saveMatchStats' export * from './saveMatchStats'
export * from './getGeoInfo'
export * from './getTokenVirtualUser' export * from './getTokenVirtualUser'

Loading…
Cancel
Save