fix(#242): add route for get selected subscriptions

pull/33/head
Andrei Dekterev 3 years ago
parent f15ea1c466
commit 8c28c0d1b3
  1. 6
      src/features/MatchPage/components/SubscriptionGuard/index.tsx
  2. 5
      src/helpers/parseUrlParams/parseUrlParams.tsx
  3. 15
      src/requests/getSelectedSubscriptions.tsx

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

@ -7,3 +7,8 @@ export const checkUrlParams = (key: string) => {
const params = new URLSearchParams(window.location.search)
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