From 8c28c0d1b3a23907d853f1c1c2a1a2a90a105a8c Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Sat, 14 Jan 2023 09:06:45 +0700 Subject: [PATCH] fix(#242): add route for get selected subscriptions --- .../components/SubscriptionGuard/index.tsx | 6 +++++- src/helpers/parseUrlParams/parseUrlParams.tsx | 5 +++++ src/requests/getSelectedSubscriptions.tsx | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/requests/getSelectedSubscriptions.tsx diff --git a/src/features/MatchPage/components/SubscriptionGuard/index.tsx b/src/features/MatchPage/components/SubscriptionGuard/index.tsx index 01286d17..61278d03 100644 --- a/src/features/MatchPage/components/SubscriptionGuard/index.tsx +++ b/src/features/MatchPage/components/SubscriptionGuard/index.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, diff --git a/src/helpers/parseUrlParams/parseUrlParams.tsx b/src/helpers/parseUrlParams/parseUrlParams.tsx index f960c546..2d02baef 100644 --- a/src/helpers/parseUrlParams/parseUrlParams.tsx +++ b/src/helpers/parseUrlParams/parseUrlParams.tsx @@ -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) +} diff --git a/src/requests/getSelectedSubscriptions.tsx b/src/requests/getSelectedSubscriptions.tsx new file mode 100644 index 00000000..95050c6a --- /dev/null +++ b/src/requests/getSelectedSubscriptions.tsx @@ -0,0 +1,15 @@ +import { callApi } from 'helpers' +import { Subscriptions } from './getSubscriptions' +import { API_ROOT } from '../config' + +export const getSelectedSubscriptions = async ( +): Promise => { + const config = { + method: 'GET', + } + + return callApi({ + config, + url: `${API_ROOT}/v1/subscriptions${window.location.search}`, + }) +}