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_button: 20083,
inactive_description_1: 20084, inactive_description_1: 20084,
inactive_description_2: 20086, inactive_description_2: 20086,
inactive_period: 801,
inactive_title_1: 20087, inactive_title_1: 20087,
inactive_title_2: 20088, inactive_title_2: 20088,
} }

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

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

Loading…
Cancel
Save