From a8ff5fff2c61c0392b2244fb4f614e891a790777 Mon Sep 17 00:00:00 2001 From: nevainero Date: Fri, 18 Feb 2022 12:21:55 +0300 Subject: [PATCH] feat(ott-2268): add redirect to tournament page if match didn't started --- .../MatchPage/hooks/useMatchProfile.tsx | 9 ++++++ src/features/MatchPage/index.tsx | 30 +++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/features/MatchPage/hooks/useMatchProfile.tsx b/src/features/MatchPage/hooks/useMatchProfile.tsx index d64be61e..6da293fc 100644 --- a/src/features/MatchPage/hooks/useMatchProfile.tsx +++ b/src/features/MatchPage/hooks/useMatchProfile.tsx @@ -9,6 +9,8 @@ import { getMatchInfo } from 'requests' import { usePageParams } from 'hooks/usePageParams' +import { parseDate } from 'helpers/parseDate' + import type { Playlists } from '../types' import { useMatchData } from './useMatchData' @@ -46,8 +48,15 @@ export const useMatchProfile = () => { [matchProfile, matchPlaylists], ) + const isStarted = useMemo(() => ( + profile?.date + ? parseDate(profile.date) < new Date() + : true + ), [profile?.date]) + return { events, + isStarted, profile, } } diff --git a/src/features/MatchPage/index.tsx b/src/features/MatchPage/index.tsx index e1293043..2ee3985f 100644 --- a/src/features/MatchPage/index.tsx +++ b/src/features/MatchPage/index.tsx @@ -1,3 +1,5 @@ +import { useHistory } from 'react-router' + import { usePageLogger } from 'hooks/usePageLogger' import { ProfileHeader } from 'features/ProfileHeader' @@ -16,11 +18,23 @@ import { Wrapper } from './styled' const MatchPage = () => { usePageLogger() - const { events, profile } = useMatchProfile() + const history = useHistory() + + const { + events, + isStarted, + profile, + } = useMatchProfile() const playFromScout = profile?.has_video && !profile?.live const playFromOTT = !profile?.has_video && (profile?.live || profile?.storage) + // TODO Добавить попап 'Данный матч ещё не начался' + if (!isStarted && profile) { + const sportName = history.location.pathname.split('/')[1] + history.push(`/${sportName}/tournaments/${profile.tournament.id}`) + } + return ( @@ -30,8 +44,18 @@ const MatchPage = () => { - {playFromOTT && } - {playFromScout && } + {playFromOTT && ( + + )} + {playFromScout && ( + + )}