From c67bc5a22c2296bd83b881f0c49cc8cc55fe179f Mon Sep 17 00:00:00 2001 From: andreidekterev Date: Thu, 29 Jun 2023 19:38:17 +0700 Subject: [PATCH] fix(#689): add tournament info for default landing --- src/config/lexics/landingLexics.tsx | 1 + src/features/Landings/hooks.tsx | 49 ++++++++++++++++++++++------- src/features/Landings/index.tsx | 13 +++++--- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/config/lexics/landingLexics.tsx b/src/config/lexics/landingLexics.tsx index b6184100..fb81f158 100644 --- a/src/config/lexics/landingLexics.tsx +++ b/src/config/lexics/landingLexics.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, } diff --git a/src/features/Landings/hooks.tsx b/src/features/Landings/hooks.tsx index bdad0f12..3b07af12 100644 --- a/src/features/Landings/hooks.tsx +++ b/src/features/Landings/hooks.tsx @@ -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(null) @@ -29,7 +29,7 @@ export const useLandings = () => { const [nonExistLogoSrc, setNonExistLogoSrc] = useState('') const [tournamentProfile, setTournamentProfile] = useState(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, diff --git a/src/features/Landings/index.tsx b/src/features/Landings/index.tsx index c25cf191..4f2b98ac 100644 --- a/src/features/Landings/index.tsx +++ b/src/features/Landings/index.tsx @@ -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 = () => { {isInactiveLanding - ? season + ? ( + <> +  {season} + + ) :