feat(in-454): default landing

pull/150/head
Margarita 3 years ago
parent 5f93cc4717
commit 3795025519
  1. 2
      src/config/lexics/indexLexics.tsx
  2. 9
      src/config/lexics/landingLexics.tsx
  3. 4
      src/features/App/AuthenticatedApp.tsx
  4. 27
      src/features/AuthStore/hooks/useAuth.tsx
  5. 4
      src/features/Landings/TeamLogoImg/index.tsx
  6. 0
      src/features/Landings/helpers.tsx
  7. 141
      src/features/Landings/hooks.tsx
  8. 55
      src/features/Landings/index.tsx
  9. 46
      src/features/Landings/styled.tsx
  10. 18
      src/features/MatchPage/store/hooks/index.tsx
  11. 96
      src/features/TournamentLanding/hooks.tsx
  12. 38
      src/features/TournamentPage/hooks.tsx
  13. 24
      src/requests/getLanding.tsx
  14. 20
      src/requests/getLandingStatus.tsx
  15. 2
      src/requests/index.tsx

@ -3,6 +3,7 @@ import { publicLexics } from './public'
import { highlightsPageLexic } from './highlightsPageLexic' import { highlightsPageLexic } from './highlightsPageLexic'
import { mailingsLexics } from './mailings' import { mailingsLexics } from './mailings'
import { sportsLexic } from './sportsLexic' import { sportsLexic } from './sportsLexic'
import { landingLexics } from './landingLexics'
const matchPopupLexics = { const matchPopupLexics = {
actions: 1020, actions: 1020,
@ -219,4 +220,5 @@ export const indexLexics = {
...paymentLexics, ...paymentLexics,
...sportsLexic, ...sportsLexic,
...sportsPopup, ...sportsPopup,
...landingLexics,
} }

@ -0,0 +1,9 @@
export const landingLexics = {
inactive_button: 20083,
inactive_description_1: 20084,
inactive_description_2: 20086,
inactive_period: 801,
inactive_title_1: 20087,
inactive_title_2: 20088,
}

@ -35,7 +35,7 @@ const MatchPage = lazy(() => import('features/MatchPage'))
const PlayerPage = lazy(() => import('features/PlayerPage')) const PlayerPage = lazy(() => import('features/PlayerPage'))
const TournamentPage = lazy(() => import('features/TournamentPage')) const TournamentPage = lazy(() => import('features/TournamentPage'))
const SystemSettings = lazy(() => import('features/SystemSettings')) const SystemSettings = lazy(() => import('features/SystemSettings'))
const TournamentLanding = lazy(() => import('features/TournamentLanding')) const Landings = lazy(() => import('features/Landings'))
const HighlightsPage = lazy(() => import('pages/HighlightsPage')) const HighlightsPage = lazy(() => import('pages/HighlightsPage'))
const ThanksPage = lazy(() => import('pages/ThanksPage')) const ThanksPage = lazy(() => import('pages/ThanksPage'))
@ -96,7 +96,7 @@ export const AuthenticatedApp = () => {
<HighlightsPage /> <HighlightsPage />
</Route> </Route>
<Route path={`${PAGES.landing}`}> <Route path={`${PAGES.landing}`}>
<TournamentLanding /> <Landings />
</Route> </Route>
<Redirect to={PAGES.home} /> <Redirect to={PAGES.home} />
</Switch> </Switch>

@ -10,6 +10,7 @@ import type { User } from 'oidc-client'
import isString from 'lodash/isString' import isString from 'lodash/isString'
import isBoolean from 'lodash/isBoolean' import isBoolean from 'lodash/isBoolean'
import includes from 'lodash/includes'
import { PAGES } from 'config' import { PAGES } from 'config'
@ -20,7 +21,6 @@ import {
readToken, readToken,
setCookie, setCookie,
removeCookie, removeCookie,
isMatchPage,
TOKEN_KEY, TOKEN_KEY,
} from 'helpers' } from 'helpers'
@ -125,15 +125,12 @@ export const useAuth = () => {
validator: isBoolean, validator: isBoolean,
}) })
useEffect(() => { const [landingUrlFrom, setLandingUrlFrom] = useSessionStore({
if (isMatchPage()) setPage(history.location.pathname) clearOnUnmount: true,
if (history.location.pathname !== page) setIsFromLanding(false) defaultValue: '',
}, [ key: 'landingUrlFrom',
history.location.pathname, validator: isString,
page, })
setIsFromLanding,
setPage,
])
const getTemporaryToken = async () => { const getTemporaryToken = async () => {
try { try {
@ -281,7 +278,11 @@ export const useAuth = () => {
setUserInfo(userInfoFetched) setUserInfo(userInfoFetched)
userInfoFetched.language.iso && changeLang(userInfoFetched.language.iso) if (includes(window.location.pathname, PAGES.landing)) {
changeLang(navigator.language.substring(0, 2))
} else {
userInfoFetched.language.iso && changeLang(userInfoFetched.language.iso)
}
// eslint-disable-next-line no-empty // eslint-disable-next-line no-empty
} catch (error) {} } catch (error) {}
@ -295,11 +296,13 @@ export const useAuth = () => {
fetchUserInfo, fetchUserInfo,
isFromLanding, isFromLanding,
isNewDeviceLogin, isNewDeviceLogin,
landingUrlFrom,
loadingUser, loadingUser,
login, login,
logout, logout,
page, page,
setIsFromLanding, setIsFromLanding,
setLandingUrlFrom,
setPage, setPage,
setSearch, setSearch,
setUserInfo, setUserInfo,
@ -308,6 +311,7 @@ export const useAuth = () => {
}), [ }), [
fetchUserInfo, fetchUserInfo,
isNewDeviceLogin, isNewDeviceLogin,
landingUrlFrom,
logout, logout,
user, user,
userInfo, userInfo,
@ -319,6 +323,7 @@ export const useAuth = () => {
page, page,
setIsFromLanding, setIsFromLanding,
isFromLanding, isFromLanding,
setLandingUrlFrom,
]) ])
return auth return auth

@ -24,14 +24,16 @@ type Props = {
export const TeamLogoImg = ({ export const TeamLogoImg = ({
src, src,
}: Props) => { }: Props) => {
const [isLogoError, setIsImgError] = useState(false) const [isLogoError, setIsImgError] = useState(true)
const onError = () => setIsImgError(true) const onError = () => setIsImgError(true)
const onLoad = () => setIsImgError(false)
return ( return (
<LogoImg <LogoImg
src={src} src={src}
onError={onError} onError={onError}
onLoad={onLoad}
isLogoError={isLogoError} isLogoError={isLogoError}
/> />
) )

@ -0,0 +1,141 @@
import {
useEffect,
useState,
} from 'react'
import size from 'lodash/size'
import includes from 'lodash/includes'
import type { Landing } from 'requests/getLanding'
import { getLanding } from 'requests/getLanding'
import { PAGES } from 'config/pages'
import { redirectToUrl } from 'helpers/redirectToUrl'
import { useLexicsStore } from 'features/LexicsStore'
import { useAuthStore } from 'features/AuthStore'
import { getLandingName, isPastLandingDate } from './helpers'
import { getName } from '../Name'
export const useLandings = () => {
const [tournamentInfo, setTournamentInfo] = useState<Landing | null>(null)
const [isInactiveLanding, setIsInactiveLanding] = useState(false)
const { addLexicsConfig, suffix } = useLexicsStore()
const {
landingUrlFrom,
setIsFromLanding,
user,
} = useAuthStore()
const buttonLexic = tournamentInfo?.lexic_button || ''
const period = tournamentInfo?.lexic_period || ''
const title = tournamentInfo?.lexic_title || ''
const description = tournamentInfo?.lexic_description || ''
const gallery = tournamentInfo?.media.gallery
useEffect(() => {
const lexics = [buttonLexic, period, title, description]
addLexicsConfig(lexics)
}, [
addLexicsConfig,
buttonLexic,
description,
period,
title,
])
const redirectToHomePage = () => redirectToUrl(PAGES.home)
const onButtonClick = () => {
if (includes(landingUrlFrom, PAGES.match) || includes(landingUrlFrom, PAGES.tournament)) {
setIsFromLanding(true)
redirectToUrl(landingUrlFrom)
sessionStorage.removeItem('landingUrlFrom')
} else {
redirectToUrl(tournamentInfo?.url_button || '')
}
}
useEffect(() => {
(async () => {
const landingData = sessionStorage.getItem('landingData')
const parseLandingDate = landingData && JSON.parse(landingData)
try {
const date = landingUrlFrom
? await getLanding({
landingName: parseLandingDate.landing_id || parseLandingDate.url_landing,
seasonId: parseLandingDate.season_id,
sportId: parseLandingDate.sport_id,
tournamentId: parseLandingDate.tournament_id,
})
: await getLanding({ landingName: getLandingName() })
if (user) return redirectToUrl(date.url_button || '')
if (isPastLandingDate(date.date_to)) setIsInactiveLanding(true)
setTournamentInfo(date)
return sessionStorage.removeItem('landingData')
} catch (err) {
return redirectToHomePage()
}
})()
}, [landingUrlFrom, user])
const [sliderItemId, setSliderItemId] = useState(0)
const onSliderSwitchClick = (itemId: number) => setSliderItemId(itemId)
const imgCounter = size(gallery)
useEffect(() => {
if (sliderItemId === imgCounter) {
setSliderItemId(0)
}
const getSliderInterval = setInterval(() => {
setSliderItemId(sliderItemId + 1)
}, 5000)
return () => clearInterval(getSliderInterval)
}, [imgCounter, sliderItemId])
const isInactiveLandingData = () => {
if (!tournamentInfo?.tournaments || !isInactiveLanding) return null
const {
season,
tournament_eng,
tournament_rus,
} = tournamentInfo.tournaments[0]
const currentTournamentsTitle = {
name_eng: tournament_eng,
name_rus: tournament_rus,
}
const tournamentsTitle = getName({ nameObj: currentTournamentsTitle, suffix })
return {
season,
tournamentsTitle,
}
}
return {
buttonColor: tournamentInfo?.button_color,
buttonLexic,
description,
gallery,
isInactiveLanding,
isInactiveLandingData: isInactiveLandingData(),
logo: tournamentInfo?.media.logo,
logoInsports: tournamentInfo?.logo_insports,
onButtonClick,
onSliderSwitchClick,
period,
redirectToHomePage,
sliderItemId,
teams: tournamentInfo?.teams,
title,
tournamentInfo,
}
}

@ -1,3 +1,5 @@
import { Fragment } from 'react'
import format from 'date-fns/format' import format from 'date-fns/format'
import map from 'lodash/map' import map from 'lodash/map'
@ -6,7 +8,7 @@ import { isMobileDevice } from 'config/userAgent'
import { T9n } from 'features/T9n' import { T9n } from 'features/T9n'
import { useTournamentLanding } from './hooks' import { useLandings } from './hooks'
import { TeamLogoImg } from './TeamLogoImg' import { TeamLogoImg } from './TeamLogoImg'
import { import {
@ -36,12 +38,14 @@ import {
TournamentInfoContainer, TournamentInfoContainer,
} from './styled' } from './styled'
const TournamentLanding = () => { const Landings = () => {
const { const {
buttonColor, buttonColor,
buttonLexic, buttonLexic,
description, description,
gallery, gallery,
isInactiveLanding,
isInactiveLandingData,
logo, logo,
logoInsports, logoInsports,
onButtonClick, onButtonClick,
@ -52,7 +56,7 @@ const TournamentLanding = () => {
teams, teams,
title, title,
tournamentInfo, tournamentInfo,
} = useTournamentLanding() } = useLandings()
if (!tournamentInfo) return null if (!tournamentInfo) return null
@ -67,7 +71,7 @@ const TournamentLanding = () => {
<MainInfoContainer> <MainInfoContainer>
<BlockWrapper> <BlockWrapper>
{ {
gallery gallery && !isInactiveLanding
? ( ? (
<SliderWrapper> <SliderWrapper>
<SliderContainer> <SliderContainer>
@ -99,18 +103,47 @@ const TournamentLanding = () => {
} }
<TournamentInfoContainer> <TournamentInfoContainer>
<TournamentInfo> <TournamentInfo>
<DateInfo t={period} /> {isInactiveLanding
<TournamentTitle t={title} /> ? (
<TournamentDescription t={description} /> <Fragment>
<DateInfo>
<T9n t='inactive_period' />&nbsp;
{isInactiveLandingData?.season}
</DateInfo>
<TournamentTitle>
<T9n t='inactive_title_1' />&nbsp;
{isInactiveLandingData?.tournamentsTitle}&nbsp;
<T9n t='inactive_title_2' />
</TournamentTitle>
<TournamentDescription>
<T9n t='inactive_description_1' />&nbsp;
{isInactiveLandingData?.tournamentsTitle}&nbsp;
<T9n t='inactive_description_2' />
</TournamentDescription>
</Fragment>
)
: (
<Fragment>
<DateInfo>
<T9n t={period} />
</DateInfo>
<TournamentTitle>
<T9n t={title} />
</TournamentTitle>
<TournamentDescription>
<T9n t={description} />
</TournamentDescription>
</Fragment>
)}
<TournamentButton <TournamentButton
buttonColor={buttonColor} buttonColor={buttonColor}
onClick={onButtonClick} onClick={onButtonClick}
> >
<T9n t={buttonLexic} /> <T9n t={isInactiveLanding ? 'inactive_button' : buttonLexic} />
</TournamentButton> </TournamentButton>
</TournamentInfo> </TournamentInfo>
<TournamentMedia> <TournamentMedia>
{gallery && <TournamentLogo src={logo} />} {(gallery && !isInactiveLanding) && <TournamentLogo src={logo} />}
{teams && ( {teams && (
<TeamsLogo> <TeamsLogo>
{map(teams, (item) => ( {map(teams, (item) => (
@ -121,7 +154,7 @@ const TournamentLanding = () => {
))} ))}
</TeamsLogo> </TeamsLogo>
)} )}
{logoInsports && <InsportsImg src='/images/insports-logo.svg' />} {(logoInsports && !isInactiveLanding) && <InsportsImg src='/images/insports-logo.svg' />}
</TournamentMedia> </TournamentMedia>
</TournamentInfoContainer> </TournamentInfoContainer>
</BlockWrapper> </BlockWrapper>
@ -131,4 +164,4 @@ const TournamentLanding = () => {
) )
} }
export default TournamentLanding export default Landings

@ -4,7 +4,6 @@ import { isMobileDevice } from 'config/userAgent'
import { ButtonSolid } from 'features/Common' import { ButtonSolid } from 'features/Common'
import { Logo } from 'features/Logo' import { Logo } from 'features/Logo'
import { T9n } from 'features/T9n'
type ButtonProps = { type ButtonProps = {
buttonColor?: string, buttonColor?: string,
@ -24,6 +23,7 @@ export const Wrapper = styled.div`
color: white; color: white;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between;
` `
export const HeaderWrapper = styled.div` export const HeaderWrapper = styled.div`
@ -56,7 +56,7 @@ export const InsportsLogo = styled(Logo)`
` `
export const MainInfoContainer = styled.div` export const MainInfoContainer = styled.div`
height: 100%; height: 87%;
${isMobileDevice ${isMobileDevice
? css` ? css`
@ -101,6 +101,7 @@ export const MainLogoWrapper = styled.div`
width: 50%; width: 50%;
position: relative; position: relative;
align-items: center; align-items: center;
margin-right: 1%;
${isMobileDevice ${isMobileDevice
? css` ? css`
@ -113,8 +114,8 @@ export const MainLogoWrapper = styled.div`
` `
export const MainLogoImg = styled.img` export const MainLogoImg = styled.img`
width: 35%; width: 48%;
height: 35%; height: 48%;
position: relative; position: relative;
${isMobileDevice ${isMobileDevice
@ -198,7 +199,7 @@ export const SliderSwitchItem = styled.div<SliderSwitchProps>`
height: 4px; height: 4px;
border-radius: 2px; border-radius: 2px;
background-color: white; background-color: white;
opacity: ${({ slideOpacity }) => (slideOpacity ? '1' : '.3')};; opacity: ${({ slideOpacity }) => (slideOpacity ? '1' : '.3')};
margin-right: 10px; margin-right: 10px;
cursor: pointer; cursor: pointer;
transition: .7s; transition: .7s;
@ -234,14 +235,14 @@ export const TournamentInfo = styled.div`
margin-top: ${(isMobileDevice ? 'none' : '90px')}; margin-top: ${(isMobileDevice ? 'none' : '90px')};
` `
export const DateInfo = styled(T9n)` export const DateInfo = styled.div`
text-transform: uppercase; text-transform: uppercase;
background-color: rgba(0, 0, 0, 0.4); background-color: rgba(0, 0, 0, 0.4);
padding: 8px 25px; padding: 8px 25px;
color: #B9B9B9; color: #B9B9B9;
width: fit-content; width: fit-content;
border-radius: 5px; border-radius: 5px;
font-size: 13px; font-size: .62rem;
font-weight: 600; font-weight: 600;
${isMobileDevice ${isMobileDevice
@ -249,14 +250,14 @@ export const DateInfo = styled(T9n)`
font-size: 10px; font-size: 10px;
border-radius: 3px; border-radius: 3px;
background-color: rgba(0, 0, 0, 0.7); background-color: rgba(0, 0, 0, 0.7);
padding: 5px 10px;` padding: 3px 10px;`
: ''}; : ''};
` `
export const TournamentTitle = styled(T9n)` export const TournamentTitle = styled.div`
font-weight: 700; font-weight: 700;
font-size: 50px; font-size: 2.36rem;
margin-top: 50px; margin-top: 2.4rem;
${isMobileDevice ${isMobileDevice
? css` ? css`
@ -271,11 +272,13 @@ export const TournamentTitle = styled(T9n)`
export const TournamentButton = styled(ButtonSolid)<ButtonProps>` export const TournamentButton = styled(ButtonSolid)<ButtonProps>`
width: 320px; width: 320px;
height: fit-content; height: fit-content;
font-size: 24px; font-size: 1.13rem;
font-weight: 600; font-weight: 600;
border-radius: 5px; border-radius: 5px;
margin-bottom: 90px; margin-bottom: 4.25rem;
padding: 20px 0; padding: 0.94rem 3rem;
display: flex;
justify-content: center;
background-color: ${({ buttonColor }) => (buttonColor ? `${buttonColor}` : '#294FC3')}; background-color: ${({ buttonColor }) => (buttonColor ? `${buttonColor}` : '#294FC3')};
${isMobileDevice ${isMobileDevice
@ -288,16 +291,17 @@ export const TournamentButton = styled(ButtonSolid)<ButtonProps>`
: ''}; : ''};
` `
export const TournamentDescription = styled(T9n)` export const TournamentDescription = styled.div`
max-width: 400px; max-width: 26.6rem;
margin: 50px 0; margin: 2.4rem 0;
font-size: 17px; font-size: 0.8rem;
letter-spacing: 0.1px;
line-height: 150%;
${isMobileDevice ${isMobileDevice
? css` ? css`
max-width: 100%;
font-size: 12px; font-size: 12px;
line-height: 150%;
letter-spacing: 0.1px;
margin: 25px 0 30px; margin: 25px 0 30px;
` `
: ''}; : ''};
@ -307,7 +311,7 @@ export const TournamentMedia = styled.div`
display: flex; display: flex;
align-items: center; align-items: center;
height: 130px; height: 130px;
margin-bottom: 25px; margin-bottom: 1.2rem;
${isMobileDevice ${isMobileDevice
? css` ? css`

@ -3,6 +3,7 @@ import {
useState, useState,
useMemo, useMemo,
} from 'react' } from 'react'
import { useHistory } from 'react-router'
import includes from 'lodash/includes' import includes from 'lodash/includes'
import filter from 'lodash/filter' import filter from 'lodash/filter'
@ -79,10 +80,13 @@ export const useMatchPage = () => {
const { const {
isFromLanding, isFromLanding,
landingUrlFrom,
setIsFromLanding, setIsFromLanding,
setLandingUrlFrom,
user, user,
userInfo, userInfo,
} = useAuthStore() } = useAuthStore()
const history = useHistory()
const { const {
close: hideProfileCard, close: hideProfileCard,
@ -138,14 +142,22 @@ export const useMatchPage = () => {
})) }))
useEffect(() => { useEffect(() => {
if (user || isFromLanding) return if (user || isFromLanding || history.length > 1) return
getLandingStatus({ matchId, sportType }) getLandingStatus({ matchId, sportType })
.then(({ landing_id }) => { .then((data) => {
setLandingUrlFrom(window.location.pathname)
sessionStorage.setItem(
'landingData',
JSON.stringify(data),
)
setIsFromLanding(false) setIsFromLanding(false)
if (landing_id) redirectToUrl(`${PAGES.landing}/${landing_id}`) if (data.landing_id) redirectToUrl(`${PAGES.landing}/${data.landing_id}`)
}) })
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ }, [
setLandingUrlFrom,
isFromLanding, isFromLanding,
landingUrlFrom,
matchId, matchId,
setIsFromLanding, setIsFromLanding,
sportType, sportType,

@ -1,96 +0,0 @@
import {
useEffect,
useState,
} from 'react'
import size from 'lodash/size'
import includes from 'lodash/includes'
import type { TournamentLanding } from 'requests/getTournamentLanding'
import { getTournamentLanding } from 'requests/getTournamentLanding'
import { PAGES } from 'config/pages'
import { redirectToUrl } from 'helpers/redirectToUrl'
import { useLexicsStore } from 'features/LexicsStore'
import { useAuthStore } from 'features/AuthStore'
import { getLandingName, isPastLandingDate } from './helpers'
export const useTournamentLanding = () => {
const [tournamentInfo, setTournamentInfo] = useState<TournamentLanding | null>(null)
const { addLexicsConfig } = useLexicsStore()
const { page, setIsFromLanding } = useAuthStore()
const buttonLexic = tournamentInfo?.lexic_button || ''
const period = tournamentInfo?.lexic_period || ''
const title = tournamentInfo?.lexic_title || ''
const description = tournamentInfo?.lexic_description || ''
const gallery = tournamentInfo?.media.gallery
useEffect(() => {
const lexics = [buttonLexic, period, title, description]
addLexicsConfig(lexics)
}, [
addLexicsConfig,
buttonLexic,
description,
period,
title,
])
const redirectToHomePage = () => redirectToUrl(PAGES.home)
const onButtonClick = () => {
if (includes(page, 'matches')) {
setIsFromLanding(true)
redirectToUrl(page)
} else {
redirectToUrl(tournamentInfo?.url_button || '')
}
}
useEffect(() => {
getTournamentLanding(getLandingName())
.then((data) => (
isPastLandingDate(data.date_to)
? redirectToHomePage()
: setTournamentInfo(data)
))
.catch(redirectToHomePage)
}, [])
const [sliderItemId, setSliderItemId] = useState(0)
const onSliderSwitchClick = (itemId: number) => setSliderItemId(itemId)
const imgCounter = size(gallery)
useEffect(() => {
if (sliderItemId === imgCounter) {
setSliderItemId(0)
}
const getSliderInterval = setInterval(() => {
setSliderItemId(sliderItemId + 1)
}, 5000)
return () => clearInterval(getSliderInterval)
}, [imgCounter, sliderItemId])
return {
buttonColor: tournamentInfo?.button_color,
buttonLexic,
description,
gallery,
logo: tournamentInfo?.media.logo,
logoInsports: tournamentInfo?.logo_insports,
onButtonClick,
onSliderSwitchClick,
period,
redirectToHomePage,
sliderItemId,
teams: tournamentInfo?.teams,
title,
tournamentInfo,
}
}

@ -11,13 +11,18 @@ import {
getTournamentMatches, getTournamentMatches,
} from 'requests' } from 'requests'
import { openSubscribePopup, redirectToUrl } from 'helpers'
import { PAGES } from 'config/pages'
import { useName } from 'features/Name'
import { checkUrlParams } from 'helpers/parseUrlParams/parseUrlParams' import { checkUrlParams } from 'helpers/parseUrlParams/parseUrlParams'
import { usePageParams } from 'hooks/usePageParams' import { usePageParams } from 'hooks/usePageParams'
import { openSubscribePopup } from 'helpers'
import { useName } from 'features/Name'
import { isPermittedTournament } from '../../helpers/isPermittedTournament' import { isPermittedTournament } from '../../helpers/isPermittedTournament'
import { getLandingStatus } from '../../requests/getLandingStatus'
import { useProfileCard } from '../ProfileCard/hooks' import { useProfileCard } from '../ProfileCard/hooks'
import { useBuyMatchPopupStore } from '../BuyMatchPopup' import { useBuyMatchPopupStore } from '../BuyMatchPopup'
import { MATCH_CONFIG } from '../BuyMatchPopup/store/hooks/useSubscriptions' import { MATCH_CONFIG } from '../BuyMatchPopup/store/hooks/useSubscriptions'
@ -30,7 +35,12 @@ export const useTournamentPage = () => {
const country = useName(tournamentProfile?.country || {}) const country = useName(tournamentProfile?.country || {})
const history = useHistory() const history = useHistory()
const { user } = useAuthStore() const {
isFromLanding,
setIsFromLanding,
setLandingUrlFrom,
user,
} = useAuthStore()
const { isFavorite, toggleFavorites } = useProfileCard() const { isFavorite, toggleFavorites } = useProfileCard()
@ -47,6 +57,28 @@ export const useTournamentPage = () => {
tournamentId, tournamentId,
]) ])
useEffect(() => {
if (user || isFromLanding || history.length > 1) return
getLandingStatus({ sportType, tournamentId })
.then((data) => {
setLandingUrlFrom(window.location.pathname)
sessionStorage.setItem(
'landingData',
JSON.stringify(data),
)
setIsFromLanding(false)
if (data.landing_id) redirectToUrl(`${PAGES.landing}/${data.landing_id}`)
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
setLandingUrlFrom,
isFromLanding,
tournamentId,
setIsFromLanding,
sportType,
user,
])
useEffect(() => { useEffect(() => {
!isFavorite !isFavorite
&& checkUrlParams('from') === 'landing' && checkUrlParams('from') === 'landing'

@ -1,3 +1,5 @@
import isUndefined from 'lodash/isUndefined'
import { API_ROOT } from 'config' import { API_ROOT } from 'config'
import { callApi } from 'helpers' import { callApi } from 'helpers'
@ -25,7 +27,7 @@ type Gallery = {
url: string, url: string,
} }
export type TournamentLanding = { export type Landing = {
button_color?: string, button_color?: string,
date_from: string, date_from: string,
date_to: string, date_to: string,
@ -42,19 +44,31 @@ export type TournamentLanding = {
}, },
name: string, name: string,
teams: Array<Teams>, teams: Array<Teams>,
tournaments: Array<Tournaments>, tournaments: Array<Tournaments> | null,
url_button?: string, url_button?: string,
} }
export const getTournamentLanding = async ( type Args = {
landingName: number | string, landingName: number | string,
): Promise<TournamentLanding> => { seasonId?: number,
sportId?: number,
tournamentId?: number,
}
export const getLanding = async ({
landingName,
seasonId,
sportId,
tournamentId,
}: Args): Promise<Landing> => {
const config = { const config = {
method: 'GET', method: 'GET',
} }
return callApi({ return callApi({
config, config,
url: `${API_ROOT}/v1/landings/${landingName}`, url: `${API_ROOT}/v1/landings/${landingName}${isUndefined(seasonId)
? ''
: `?season_id=${seasonId}&sport_id=${sportId}&tournament_id=${tournamentId}`}`,
}) })
} }

@ -1,21 +1,35 @@
import isUndefined from 'lodash/isUndefined'
import { API_ROOT } from 'config' import { API_ROOT } from 'config'
import { callApi } from 'helpers' import { callApi } from 'helpers'
type Args = { type Args = {
matchId: number, matchId?: number,
sportType: number, sportType: number,
tournamentId?: number,
}
type LandingStatus = {
landing_id: number,
season_id: number,
sport_id: number,
tournament_id: number,
url_landing: string,
} }
export const getLandingStatus = async ({ export const getLandingStatus = async ({
matchId, matchId,
sportType, sportType,
}: Args): Promise<{landing_id: number | null}> => { tournamentId,
}: Args): Promise<LandingStatus> => {
const config = { const config = {
method: 'GET', method: 'GET',
} }
return callApi({ return callApi({
config, config,
url: `${API_ROOT}/v1/landings/${sportType}/${matchId}/status`, url: `${API_ROOT}/v1/landings/status/${sportType}?${
isUndefined(matchId) ? '' : `match_id=${matchId}`}${
isUndefined(tournamentId) ? '' : `tournament_id=${tournamentId}`}`,
}) })
} }

@ -8,7 +8,7 @@ export * from './getUserSportFavs'
export * from './modifyUserSportFavs' export * from './modifyUserSportFavs'
export * from './getSportTournaments' export * from './getSportTournaments'
export * from './getTournamentInfo' export * from './getTournamentInfo'
export * from './getTournamentLanding' export * from './getLanding'
export * from './getTeamInfo' export * from './getTeamInfo'
export * from './getUserInfo' export * from './getUserInfo'
export * from './getMatchInfo' export * from './getMatchInfo'

Loading…
Cancel
Save