feat(ott-821): add new conditions for match popup (#317)

* feat(ott-821): add new conditions for match popup

* style(ott-821): refactoring import
keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
Иван Пиминов 5 years ago committed by GitHub
parent 29848337dd
commit 5050f12507
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      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<HTMLLIElement>) => {

Loading…
Cancel
Save