|
|
|
|
@ -6,19 +6,28 @@ import { |
|
|
|
|
import { useHistory } from 'react-router' |
|
|
|
|
|
|
|
|
|
import type { TournamentInfo } from 'requests' |
|
|
|
|
import { getTournamentInfo, getTournamentMatches } from 'requests' |
|
|
|
|
import { |
|
|
|
|
getMatchInfo, |
|
|
|
|
getTournamentInfo, |
|
|
|
|
getTournamentMatches, |
|
|
|
|
MatchInfo, |
|
|
|
|
} from 'requests' |
|
|
|
|
|
|
|
|
|
import { checkUrlParams } from 'helpers/parseUrlParams/parseUrlParams' |
|
|
|
|
import { checkUrlParams, getAllUrlParams } from 'helpers/parseUrlParams/parseUrlParams' |
|
|
|
|
|
|
|
|
|
import { usePageParams } from 'hooks/usePageParams' |
|
|
|
|
|
|
|
|
|
import { useName } from 'features/Name' |
|
|
|
|
import { isPermittedTournament } from '../../helpers/isPermittedTournament' |
|
|
|
|
import { useProfileCard } from '../ProfileCard/hooks' |
|
|
|
|
import { useBuyMatchPopupStore } from '../BuyMatchPopup' |
|
|
|
|
import { MATCH_CONFIG } from '../BuyMatchPopup/store/hooks/useSubscriptions' |
|
|
|
|
import { prepareMatchProfile } from '../MatchPage/helpers/prepareMatchProfile' |
|
|
|
|
|
|
|
|
|
export const useTournamentPage = () => { |
|
|
|
|
const [tournamentProfile, setTournamentProfile] = useState<TournamentInfo>(null) |
|
|
|
|
const { profileId: tournamentId, sportType } = usePageParams() |
|
|
|
|
const { open: openBuyMatchPopup } = useBuyMatchPopupStore() |
|
|
|
|
const country = useName(tournamentProfile?.country || {}) |
|
|
|
|
const history = useHistory() |
|
|
|
|
|
|
|
|
|
@ -63,6 +72,22 @@ export const useTournamentPage = () => { |
|
|
|
|
name_rus: tournamentProfile.name_rus, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if ((checkUrlParams('subscribe') |
|
|
|
|
&& getAllUrlParams('id'))) { |
|
|
|
|
getMatchInfo(MATCH_CONFIG.sportId, MATCH_CONFIG.matchId) |
|
|
|
|
.then((match: MatchInfo) => { |
|
|
|
|
const matchProfile = match && prepareMatchProfile({ |
|
|
|
|
matchId: MATCH_CONFIG.matchId, |
|
|
|
|
profile: match, |
|
|
|
|
sportType: MATCH_CONFIG.sportId, |
|
|
|
|
}) |
|
|
|
|
matchProfile && openBuyMatchPopup(matchProfile) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
fetchMatches, |
|
|
|
|
headerImage: tournamentProfile?.header_image, |
|
|
|
|
|