You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
spa_instat_tv/src/features/Matches/helpers/getMatchClickAction/index.tsx

46 lines
1.4 KiB

import type { Match } from 'requests'
import type { User } from 'oidc-client'
import { isFuture } from 'date-fns'
import { isSubscribePopup } from '../../../../helpers'
export enum MatchAccess {
CanBuyMatch = 'CanBuyMatch',
NoAccess = 'NoAccess',
NoCountryAccess = 'NoCountryAccess',
RedirectToProfile = 'RedirectToProfile',
ViewMatchPopup = 'ViewMatchPopup',
ViewMatchPopupWithoutUser = 'ViewMatchPopupWithoutUser',
}
export const getMatchAccess = (match: Match, user: User | undefined) => {
const {
access,
date,
live,
sub,
} = match
const dateToMs = Date.parse(date?.replace(/ /, 'T')) // без замены не будет работать в сафари
const dateNowMin10 = dateToMs - 10 * 60 * 1000
const matchDate = new Date(date)
const isFutureDate = isFuture(matchDate)
switch (true) {
case !user && isFutureDate:
return MatchAccess.NoAccess
case !user && !isSubscribePopup():
return MatchAccess.ViewMatchPopupWithoutUser
case !sub:
return MatchAccess.CanBuyMatch
case !access:
return MatchAccess.NoCountryAccess
// проверка времени матча - 10минут
case ((new Date(dateNowMin10) < new Date()) && !live):
return MatchAccess.RedirectToProfile
case live:
return MatchAccess.ViewMatchPopup
default:
return MatchAccess.NoAccess
}
}