From 5050f12507b03cc0ea62feeaa65842a618fb20cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=9F=D0=B8=D0=BC=D0=B8=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2?= <61900450+ivan-piminov@users.noreply.github.com> Date: Thu, 4 Mar 2021 14:58:48 +0300 Subject: [PATCH] feat(ott-821): add new conditions for match popup (#317) * feat(ott-821): add new conditions for match popup * style(ott-821): refactoring import --- src/features/MatchCard/hooks.tsx | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/features/MatchCard/hooks.tsx b/src/features/MatchCard/hooks.tsx index 70fd1d49..f391d9fd 100644 --- a/src/features/MatchCard/hooks.tsx +++ b/src/features/MatchCard/hooks.tsx @@ -1,18 +1,35 @@ import type { KeyboardEvent } from 'react' import { useCallback } from 'react' +import { useHistory } from 'react-router-dom' import type { Match } from 'features/Matches' import { useMatchPopupStore } from 'features/MatchPopup' import { useBuyMatchPopupStore } from 'features/BuyMatchPopup' +import { getProfileUrl } from '../ProfileLink/helpers' +import { ProfileTypes } from '../../config' export const useCard = (match: Match) => { const { openPopup, setMatch } = useMatchPopupStore() const { open: openBuyMatchPopup } = useBuyMatchPopupStore() - + const history = useHistory() + const redirectToMatchPage = useCallback(() => { + const matchLink = getProfileUrl({ + id: match.id, + profileType: ProfileTypes.MATCHES, + sportType: match.sportType, + }) + return history.push(matchLink) + }, [ + history, + match.id, + match.sportType, + ]) const openMatchPopup = useCallback(() => { - if (match.isClickable) { + if (match.isClickable && match.calc && match.hasVideo) { setMatch(match) openPopup() + } else if (match.calc && !match.hasVideo) { + redirectToMatchPage() } else if (!match.accessibleBySubscription) { openBuyMatchPopup(match) } @@ -21,6 +38,7 @@ export const useCard = (match: Match) => { openPopup, openBuyMatchPopup, setMatch, + redirectToMatchPage, ]) const onKeyPress = useCallback((e: KeyboardEvent) => {