fix(#689): add tournament info for default landing

pull/265/head
andreidekterev 2 years ago committed by Gitea
parent 247a08902d
commit c67bc5a22c
  1. 1
      src/config/lexics/landingLexics.tsx
  2. 49
      src/features/Landings/hooks.tsx
  3. 13
      src/features/Landings/index.tsx

@ -3,6 +3,7 @@ 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,
}

@ -20,7 +20,7 @@ import { useLexicsStore } from 'features/LexicsStore'
import { useAuthStore } from 'features/AuthStore'
import { getLandingName, isPastLandingDate } from './helpers'
import { useName } from '../Name'
import { getName, useName } from '../Name'
export const useLandings = () => {
const [tournamentInfo, setTournamentInfo] = useState<Landing | null>(null)
@ -29,7 +29,7 @@ export const useLandings = () => {
const [nonExistLogoSrc, setNonExistLogoSrc] = useState('')
const [tournamentProfile, setTournamentProfile] = useState<TournamentInfo>(null)
const { addLexicsConfig } = useLexicsStore()
const { addLexicsConfig, suffix } = useLexicsStore()
const {
landingUrlFrom,
setIsFromLanding,
@ -67,15 +67,15 @@ export const useLandings = () => {
useEffect(() => {
(async () => {
const landingData = sessionStorage.getItem('landingData')
const parseLandingDate = landingData && JSON.parse(landingData)
const parseLandingData = landingData && JSON.parse(landingData)
if (parseLandingDate && parseLandingDate.defaultLanding) {
setIsNonExistLanding(true)
getTournamentInfo(parseLandingDate.sportType, parseLandingDate.tournamentId)
if (parseLandingData && parseLandingData.defaultLanding) {
getTournamentInfo(parseLandingData.sportType, parseLandingData.tournamentId)
.then(setTournamentProfile)
setIsNonExistLanding(true)
return getLandingLogo({
sport_id: parseLandingDate.sportType,
tournament_id: parseLandingDate.tournamentId,
sport_id: parseLandingData.sportType,
tournament_id: parseLandingData.tournamentId,
})
.then(({ logo_url }) => setNonExistLogoSrc(logo_url || '/images/tournament-fallback.png'))
}
@ -83,15 +83,17 @@ export const useLandings = () => {
try {
const data = landingUrlFrom
? await getLanding({
landingName: parseLandingDate.landing_id || parseLandingDate.url_landing,
seasonId: parseLandingDate.season_id,
sportId: parseLandingDate.sport_id,
tournamentId: parseLandingDate.tournament_id,
landingName: parseLandingData.landing_id || parseLandingData.url_landing,
seasonId: parseLandingData.season_id,
sportId: parseLandingData.sport_id,
tournamentId: parseLandingData.tournament_id,
})
: await getLanding({ landingName: getLandingName() })
if (user) return redirectToUrl(data.url_button || '')
if (isPastLandingDate(data.date_to)) setIsInactiveLanding(true)
return setTournamentInfo(data)
} catch (err) {
return redirectToHomePage()
@ -115,6 +117,28 @@ export const useLandings = () => {
return () => clearInterval(getSliderInterval)
}, [imgCounter, sliderItemId])
const inActiveLandingData = () => {
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,
}
}
const defaultTournamentName = useName(tournamentProfile || {})
return {
@ -123,6 +147,7 @@ export const useLandings = () => {
defaultTournamentName,
description,
gallery,
inActiveLandingData,
isInactiveLanding,
isNonExistLanding,
logo: tournamentInfo?.media.logo,

@ -41,15 +41,13 @@ import {
} from './styled'
const Landings = () => {
const season = checkUrlParams('season')
const tournamentName = checkUrlParams('tournament')
const {
buttonColor,
buttonLexic,
defaultTournamentName,
description,
gallery,
inActiveLandingData,
isInactiveLanding,
isNonExistLanding,
logo,
@ -65,6 +63,9 @@ const Landings = () => {
tournamentInfo,
} = useLandings()
const season = checkUrlParams('season') ?? inActiveLandingData()?.season
const tournamentName = checkUrlParams('tournament') ?? inActiveLandingData()?.tournamentsTitle
const fallbackSrc = '/images/tournament-fallback.png'
if ((!tournamentInfo && !isNonExistLanding)
@ -121,7 +122,11 @@ const Landings = () => {
<Fragment>
<DateInfo>
{isInactiveLanding
? season
? (
<>
<T9n t='inactive_period' />&nbsp;{season}
</>
)
: <T9n t='default_season' />}&nbsp;
</DateInfo>

Loading…
Cancel
Save