IN-242-subscribes #33

Merged
andrey.dekterev merged 2 commits from IN-242-subscribes into develop 3 years ago
  1. 21
      src/features/BuyMatchPopup/components/SelectSubscription/index.tsx
  2. 14
      src/features/BuyMatchPopup/store/hooks/useSubscriptions.tsx
  3. 6
      src/features/MatchPage/components/SubscriptionGuard/index.tsx
  4. 29
      src/features/TournamentPage/hooks.tsx
  5. 5
      src/helpers/parseUrlParams/parseUrlParams.tsx
  6. 15
      src/requests/getSelectedSubscriptions.tsx

@ -32,6 +32,7 @@ import {
ChooseSubItem, ChooseSubItem,
ChooseSubList, ChooseSubList,
} from './styled' } from './styled'
import { checkUrlParams, getAllUrlParams } from '../../../../helpers/parseUrlParams/parseUrlParams'
export const SelectSubscriptionStep = () => { export const SelectSubscriptionStep = () => {
const { const {
@ -55,14 +56,18 @@ export const SelectSubscriptionStep = () => {
return ( return (
<Wrapper> <Wrapper>
<Header> <Header>
<HeaderTitle> {(!checkUrlParams('subscribe')
<Names nameObj={match.team1} /> && !getAllUrlParams('id'))
{` ${MDASH} `} && (
<Names nameObj={match.team2} /> <HeaderTitle>
<ChooseSub> <Names nameObj={match.team1} />
<T9n t='choose_subscription' /> {` ${MDASH} `}
</ChooseSub> <Names nameObj={match.team2} />
</HeaderTitle> <ChooseSub>
<T9n t='choose_subscription' />
</ChooseSub>
</HeaderTitle>
)}
<HeaderActions position='right'> <HeaderActions position='right'>
<CloseButton onClick={close} /> <CloseButton onClick={close} />
</HeaderActions> </HeaderActions>

@ -22,6 +22,7 @@ import type {
import { SubscriptionType } from '../../types' import { SubscriptionType } from '../../types'
import { transformSubscriptions } from '../helpers' import { transformSubscriptions } from '../helpers'
import { useSubscriptionsLexics } from './useSubscriptionsLexics' import { useSubscriptionsLexics } from './useSubscriptionsLexics'
import { checkUrlParams } from '../../../../helpers/parseUrlParams/parseUrlParams'
const defaultSubscriptions: MatchSubscriptions = [] const defaultSubscriptions: MatchSubscriptions = []
const defaultPeriod = SubscriptionType.Month const defaultPeriod = SubscriptionType.Month
@ -36,6 +37,11 @@ const getInitialPeriod = (subscription?: MatchSubscription) => {
|| defaultPeriod || defaultPeriod
} }
export const MATCH_CONFIG = {
matchId: 2376841,
sportId: 1,
}
export const useSubscriptions = () => { export const useSubscriptions = () => {
const { suffix } = useLexicsStore() const { suffix } = useLexicsStore()
const { fetchLexics } = useSubscriptionsLexics() const { fetchLexics } = useSubscriptionsLexics()
@ -55,7 +61,13 @@ export const useSubscriptions = () => {
] = useState<MatchPackage | null>(null) ] = useState<MatchPackage | null>(null)
const fetchSubscriptions = useCallback(async (match: Match) => { const fetchSubscriptions = useCallback(async (match: Match) => {
const subscriptions = await getSubscriptions(match.sportType, match.id) let subscriptions
if (checkUrlParams('id') && checkUrlParams('subscribe')) {
subscriptions = await getSubscriptions(MATCH_CONFIG.sportId, MATCH_CONFIG.matchId)
} else {
subscriptions = await getSubscriptions(match.sportType, match.id)
}
const convertedSubscriptions = transformSubscriptions({ const convertedSubscriptions = transformSubscriptions({
match, match,
subscriptions, subscriptions,

@ -7,6 +7,7 @@ import { useBuyMatchPopupStore } from 'features/BuyMatchPopup'
import { useMatchPageStore } from 'features/MatchPage/store' import { useMatchPageStore } from 'features/MatchPage/store'
import { prepareMatchProfile } from '../../helpers/prepareMatchProfile' import { prepareMatchProfile } from '../../helpers/prepareMatchProfile'
import { checkUrlParams, getAllUrlParams } from '../../../../helpers/parseUrlParams/parseUrlParams'
type Props = { type Props = {
children: ReactNode, children: ReactNode,
@ -18,7 +19,10 @@ export const SubscriptionGuard = ({ children }: Props) => {
const { profileId: matchId, sportType } = usePageParams() const { profileId: matchId, sportType } = usePageParams()
useEffect(() => { useEffect(() => {
if (matchProfile && !matchProfile.sub) { if (matchProfile && (
!matchProfile.sub
|| (checkUrlParams('subscribe')
&& getAllUrlParams('id')))) {
const profile = prepareMatchProfile({ const profile = prepareMatchProfile({
matchId, matchId,
profile: matchProfile, profile: matchProfile,

@ -6,19 +6,28 @@ import {
import { useHistory } from 'react-router' import { useHistory } from 'react-router'
import type { TournamentInfo } from 'requests' 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 { usePageParams } from 'hooks/usePageParams'
import { useName } from 'features/Name' import { useName } from 'features/Name'
import { isPermittedTournament } from '../../helpers/isPermittedTournament' import { isPermittedTournament } from '../../helpers/isPermittedTournament'
import { useProfileCard } from '../ProfileCard/hooks' 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 = () => { export const useTournamentPage = () => {
const [tournamentProfile, setTournamentProfile] = useState<TournamentInfo>(null) const [tournamentProfile, setTournamentProfile] = useState<TournamentInfo>(null)
const { profileId: tournamentId, sportType } = usePageParams() const { profileId: tournamentId, sportType } = usePageParams()
const { open: openBuyMatchPopup } = useBuyMatchPopupStore()
const country = useName(tournamentProfile?.country || {}) const country = useName(tournamentProfile?.country || {})
const history = useHistory() const history = useHistory()
@ -63,6 +72,22 @@ export const useTournamentPage = () => {
name_rus: tournamentProfile.name_rus, 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 { return {
fetchMatches, fetchMatches,
headerImage: tournamentProfile?.header_image, headerImage: tournamentProfile?.header_image,

@ -7,3 +7,8 @@ export const checkUrlParams = (key: string) => {
const params = new URLSearchParams(window.location.search) const params = new URLSearchParams(window.location.search)
return params.get(key) return params.get(key)
} }
export const getAllUrlParams = (key: string) => {
const params = new URLSearchParams(window.location.search)
return params.getAll(key)
}

@ -0,0 +1,15 @@
import { callApi } from 'helpers'
import { Subscriptions } from './getSubscriptions'
import { API_ROOT } from '../config'
export const getSelectedSubscriptions = async (
): Promise<Subscriptions> => {
const config = {
method: 'GET',
}
return callApi({
config,
url: `${API_ROOT}/v1/subscriptions${window.location.search}`,
})
}
Loading…
Cancel
Save