From 40369dcdedbb00e8da204ca66376c90aa6081c59 Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Wed, 25 Jan 2023 18:05:51 +0700 Subject: [PATCH 1/3] fix(#242): add packages from backend --- .../components/PackagesList/index.tsx | 14 +++++++------- .../components/SelectSubscription/index.tsx | 3 ++- src/features/BuyMatchPopup/store/hooks/index.tsx | 2 +- .../BuyMatchPopup/store/hooks/useSubscriptions.tsx | 10 +++++++++- src/features/TournamentPage/hooks.tsx | 6 +++--- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/features/BuyMatchPopup/components/PackagesList/index.tsx b/src/features/BuyMatchPopup/components/PackagesList/index.tsx index bef24119..a92415c2 100644 --- a/src/features/BuyMatchPopup/components/PackagesList/index.tsx +++ b/src/features/BuyMatchPopup/components/PackagesList/index.tsx @@ -67,13 +67,13 @@ export const PackagesList = ({ /> { subPackage.type === SubscriptionType.Month - && ( - - - - ) + && ( + + + + ) } diff --git a/src/features/BuyMatchPopup/components/SelectSubscription/index.tsx b/src/features/BuyMatchPopup/components/SelectSubscription/index.tsx index 40ba62df..ba19cc19 100644 --- a/src/features/BuyMatchPopup/components/SelectSubscription/index.tsx +++ b/src/features/BuyMatchPopup/components/SelectSubscription/index.tsx @@ -17,6 +17,8 @@ import { Wrapper, } from 'features/BuyMatchPopup/styled' +import { checkUrlParams, getAllUrlParams } from 'helpers/parseUrlParams/parseUrlParams' + import { MatchPackage, SubscriptionType } from '../../types' import { @@ -32,7 +34,6 @@ import { ChooseSubItem, ChooseSubList, } from './styled' -import { checkUrlParams, getAllUrlParams } from '../../../../helpers/parseUrlParams/parseUrlParams' export const SelectSubscriptionStep = () => { const { diff --git a/src/features/BuyMatchPopup/store/hooks/index.tsx b/src/features/BuyMatchPopup/store/hooks/index.tsx index e1625fb5..328ab4de 100644 --- a/src/features/BuyMatchPopup/store/hooks/index.tsx +++ b/src/features/BuyMatchPopup/store/hooks/index.tsx @@ -89,7 +89,7 @@ export const useBuyMatchPopup = () => { const onNext = (e: MouseEvent) => goTo(Steps.SelectPackage, e) - const openPopup = useCallback((matchData: Match) => { + const openPopup = useCallback((matchData: Match | null) => { setMatch(matchData) setSteps([]) }, []) diff --git a/src/features/BuyMatchPopup/store/hooks/useSubscriptions.tsx b/src/features/BuyMatchPopup/store/hooks/useSubscriptions.tsx index 7e9710d1..abff9ea6 100644 --- a/src/features/BuyMatchPopup/store/hooks/useSubscriptions.tsx +++ b/src/features/BuyMatchPopup/store/hooks/useSubscriptions.tsx @@ -10,6 +10,7 @@ import first from 'lodash/first' import size from 'lodash/size' import { getSubscriptions } from 'requests/getSubscriptions' +import { getSelectedSubscriptions } from 'requests/getSelectedSubscriptions' import { useLexicsStore } from 'features/LexicsStore' @@ -63,7 +64,14 @@ export const useSubscriptions = () => { const fetchSubscriptions = useCallback(async (match: Match) => { let subscriptions if (checkUrlParams('id') && checkUrlParams('subscribe')) { - subscriptions = await getSubscriptions(MATCH_CONFIG.sportId, MATCH_CONFIG.matchId) + const subs = await getSelectedSubscriptions() + subscriptions = { + data: subs, + season: { + id: 0, + name: `${new Date().getFullYear()}`, + }, + } } else { subscriptions = await getSubscriptions(match.sportType, match.id) } diff --git a/src/features/TournamentPage/hooks.tsx b/src/features/TournamentPage/hooks.tsx index bc2ec773..f74ae4c5 100644 --- a/src/features/TournamentPage/hooks.tsx +++ b/src/features/TournamentPage/hooks.tsx @@ -18,13 +18,12 @@ import { checkUrlParams, getAllUrlParams } from 'helpers/parseUrlParams/parseUrl import { usePageParams } from 'hooks/usePageParams' import { useName } from 'features/Name' -import { useAuthStore } from 'features/AuthStore' - 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' +import { useAuthStore } from '../AuthStore' export const useTournamentPage = () => { const [tournamentProfile, setTournamentProfile] = useState(null) @@ -32,6 +31,7 @@ export const useTournamentPage = () => { const { open: openBuyMatchPopup } = useBuyMatchPopupStore() const country = useName(tournamentProfile?.country || {}) const history = useHistory() + const { user } = useAuthStore() const { isFavorite, toggleFavorites } = useProfileCard() @@ -77,7 +77,7 @@ export const useTournamentPage = () => { useEffect(() => { if ((checkUrlParams('subscribe') - && getAllUrlParams('id'))) { + && getAllUrlParams('id'))) { getMatchInfo(MATCH_CONFIG.sportId, MATCH_CONFIG.matchId) .then((match: MatchInfo) => { const matchProfile = match && prepareMatchProfile({ -- 2.30.2 From 9bf9f65f516841bf88f9496dfb72679a5ca55b75 Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Thu, 26 Jan 2023 21:44:01 +0700 Subject: [PATCH 2/3] fix(#242): add sub popup to player and team pages --- .../components/PackageSelectionStep/index.tsx | 49 ++++++++++--------- .../components/SelectSubscription/index.tsx | 7 ++- .../BuyMatchPopup/store/hooks/index.tsx | 8 ++- .../components/SubscriptionGuard/index.tsx | 6 +-- src/features/PlayerPage/hooks.tsx | 14 ++++++ src/features/TeamPage/hooks.tsx | 12 +++++ src/features/TournamentPage/hooks.tsx | 24 +++------ src/helpers/index.tsx | 1 + src/helpers/openSubscribePopup/index.tsx | 33 +++++++++++++ 9 files changed, 107 insertions(+), 47 deletions(-) create mode 100644 src/helpers/openSubscribePopup/index.tsx diff --git a/src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx b/src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx index c7776fb3..b7e23456 100644 --- a/src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx +++ b/src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx @@ -12,6 +12,8 @@ import { MDASH } from 'config' import { payments } from 'config/payments' import { client } from 'config/clients' +import { isSubscribePopup } from 'helpers' + import { CountryCodeType, getCountryCode } from 'requests/getCountryCode' import { CloseButton, HeaderActions } from 'features/PopupComponents' @@ -107,29 +109,32 @@ export const PackageSelectionStep = () => { return ( -
- {hasPreviousStep && ( - - - - - - )} - - {hasPreviousStep && selectedSubscription ? ( - - ) : ( - - - {` ${MDASH} `} - - + {!isSubscribePopup + && ( +
+ {hasPreviousStep && ( + + + + + + )} + + {hasPreviousStep && selectedSubscription ? ( + + ) : ( + + + {` ${MDASH} `} + + + )} + + + + +
)} -
- - - -
{!isIframePayment && } diff --git a/src/features/BuyMatchPopup/components/SelectSubscription/index.tsx b/src/features/BuyMatchPopup/components/SelectSubscription/index.tsx index ba19cc19..66c542db 100644 --- a/src/features/BuyMatchPopup/components/SelectSubscription/index.tsx +++ b/src/features/BuyMatchPopup/components/SelectSubscription/index.tsx @@ -4,6 +4,8 @@ import map from 'lodash/map' import { MDASH } from 'config' +import { isSubscribePopup } from 'helpers' + import { Name as Names } from 'features/Name' import { T9n } from 'features/T9n' import { useBuyMatchPopupStore } from 'features/BuyMatchPopup/store' @@ -17,8 +19,6 @@ import { Wrapper, } from 'features/BuyMatchPopup/styled' -import { checkUrlParams, getAllUrlParams } from 'helpers/parseUrlParams/parseUrlParams' - import { MatchPackage, SubscriptionType } from '../../types' import { @@ -57,8 +57,7 @@ export const SelectSubscriptionStep = () => { return (
- {(!checkUrlParams('subscribe') - && !getAllUrlParams('id')) + {!isSubscribePopup && ( diff --git a/src/features/BuyMatchPopup/store/hooks/index.tsx b/src/features/BuyMatchPopup/store/hooks/index.tsx index 328ab4de..7a30864c 100644 --- a/src/features/BuyMatchPopup/store/hooks/index.tsx +++ b/src/features/BuyMatchPopup/store/hooks/index.tsx @@ -34,6 +34,8 @@ import { } from 'features/BuyMatchPopup/types' import { getProfileUrl } from 'features/ProfileLink/helpers' +import { isSubscribePopup } from 'helpers' + import { useSubscriptions } from './useSubscriptions' import { useStripe3DSecure } from './useStripe3DSecure' @@ -89,7 +91,7 @@ export const useBuyMatchPopup = () => { const onNext = (e: MouseEvent) => goTo(Steps.SelectPackage, e) - const openPopup = useCallback((matchData: Match | null) => { + const openPopup = useCallback((matchData: Match) => { setMatch(matchData) setSteps([]) }, []) @@ -125,7 +127,9 @@ export const useBuyMatchPopup = () => { const onSuccessfulSubscription = () => goTo(Steps.Success) const postPaymentHandler = () => { if (!match) return - redirectToMatchProfile(match) + if (!isSubscribePopup) { + redirectToMatchProfile(match) + } closePopup() } diff --git a/src/features/MatchPage/components/SubscriptionGuard/index.tsx b/src/features/MatchPage/components/SubscriptionGuard/index.tsx index 81774c69..9c502d0a 100644 --- a/src/features/MatchPage/components/SubscriptionGuard/index.tsx +++ b/src/features/MatchPage/components/SubscriptionGuard/index.tsx @@ -6,7 +6,8 @@ import { usePageParams } from 'hooks/usePageParams' import { useBuyMatchPopupStore } from 'features/BuyMatchPopup' import { useMatchPageStore } from 'features/MatchPage/store' -import { checkUrlParams, getAllUrlParams } from 'helpers/parseUrlParams/parseUrlParams' +import { isSubscribePopup } from 'helpers' + import { prepareMatchProfile } from '../../helpers/prepareMatchProfile' import { useAuthStore } from '../../../AuthStore' @@ -23,8 +24,7 @@ export const SubscriptionGuard = ({ children }: Props) => { useEffect(() => { if (user && matchProfile && ( !matchProfile.sub - || (checkUrlParams('subscribe') - && getAllUrlParams('id')))) { + || isSubscribePopup)) { const profile = prepareMatchProfile({ matchId, profile: matchProfile, diff --git a/src/features/PlayerPage/hooks.tsx b/src/features/PlayerPage/hooks.tsx index e90c9e0d..eb56f013 100644 --- a/src/features/PlayerPage/hooks.tsx +++ b/src/features/PlayerPage/hooks.tsx @@ -9,9 +9,15 @@ import { usePageParams } from 'hooks/usePageParams' import type { PlayerProfile } from 'requests/getPlayerInfo' import { getPlayerInfo, getPlayerMatches } from 'requests' +import { openSubscribePopup } from 'helpers' + +import { MATCH_CONFIG } from '../BuyMatchPopup/store/hooks/useSubscriptions' +import { useBuyMatchPopupStore } from '../BuyMatchPopup' + export const usePlayerPage = () => { const [playerProfile, setPlayerProfile] = useState(null) const { profileId: playerId, sportType } = usePageParams() + const { open: openBuyMatchPopup } = useBuyMatchPopupStore() const { firstname_eng = '', @@ -33,6 +39,14 @@ export const usePlayerPage = () => { getPlayerInfo(playerId, sportType).then(setPlayerProfile) }, [playerId, sportType]) + useEffect(() => { + openSubscribePopup({ + matchConfig: MATCH_CONFIG, + openBuyMatchPopup, + }) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) + const fetchMatches = useCallback( (limit: number, offset: number) => getPlayerMatches({ limit, diff --git a/src/features/TeamPage/hooks.tsx b/src/features/TeamPage/hooks.tsx index d3d7b199..eb742954 100644 --- a/src/features/TeamPage/hooks.tsx +++ b/src/features/TeamPage/hooks.tsx @@ -8,10 +8,14 @@ import type { TeamInfo } from 'requests' import { getTeamInfo, getTeamMatches } from 'requests' import { usePageParams } from 'hooks/usePageParams' +import { openSubscribePopup } from '../../helpers' +import { MATCH_CONFIG } from '../BuyMatchPopup/store/hooks/useSubscriptions' +import { useBuyMatchPopupStore } from '../BuyMatchPopup' export const useTeamPage = () => { const [teamProfile, setTeamProfile] = useState(null) const { profileId: teamId, sportType } = usePageParams() + const { open: openBuyMatchPopup } = useBuyMatchPopupStore() useEffect(() => { getTeamInfo(sportType, teamId) @@ -22,6 +26,14 @@ export const useTeamPage = () => { teamId, ]) + useEffect(() => { + openSubscribePopup({ + matchConfig: MATCH_CONFIG, + openBuyMatchPopup, + }) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) + const fetchMatches = useCallback( (limit: number, offset: number) => getTeamMatches({ limit, diff --git a/src/features/TournamentPage/hooks.tsx b/src/features/TournamentPage/hooks.tsx index f74ae4c5..13a7dcbd 100644 --- a/src/features/TournamentPage/hooks.tsx +++ b/src/features/TournamentPage/hooks.tsx @@ -7,22 +7,20 @@ import { useHistory } from 'react-router' import type { TournamentInfo } from 'requests' import { - getMatchInfo, getTournamentInfo, getTournamentMatches, - MatchInfo, } from 'requests' -import { checkUrlParams, getAllUrlParams } from 'helpers/parseUrlParams/parseUrlParams' +import { checkUrlParams } from 'helpers/parseUrlParams/parseUrlParams' import { usePageParams } from 'hooks/usePageParams' +import { openSubscribePopup } from 'helpers' 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' import { useAuthStore } from '../AuthStore' export const useTournamentPage = () => { @@ -76,18 +74,12 @@ export const useTournamentPage = () => { } 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) - }) - } + openSubscribePopup( + { + matchConfig: MATCH_CONFIG, + openBuyMatchPopup, + }, + ) // eslint-disable-next-line react-hooks/exhaustive-deps }, []) diff --git a/src/helpers/index.tsx b/src/helpers/index.tsx index 356fa282..1a15820a 100644 --- a/src/helpers/index.tsx +++ b/src/helpers/index.tsx @@ -8,4 +8,5 @@ export * from './secondsToHms' export * from './redirectToUrl' export * from './getRandomString' export * from './selectedApi' +export * from './openSubscribePopup' export * from './getCurrentYear' diff --git a/src/helpers/openSubscribePopup/index.tsx b/src/helpers/openSubscribePopup/index.tsx new file mode 100644 index 00000000..838f8a8d --- /dev/null +++ b/src/helpers/openSubscribePopup/index.tsx @@ -0,0 +1,33 @@ +import type { Match } from 'features/BuyMatchPopup/types' + +import { checkUrlParams, getAllUrlParams } from '../parseUrlParams/parseUrlParams' +import { getMatchInfo, MatchInfo } from '../../requests' +import { prepareMatchProfile } from '../../features/MatchPage/helpers/prepareMatchProfile' + +type openSubscribePopupType = { + matchConfig: { + matchId: number, + sportId: number, + }, + openBuyMatchPopup: (matchProfile: Match) => void, +} + +// TODO переделать потом на открытие без запроса матча +export const openSubscribePopup = ({ + matchConfig, + openBuyMatchPopup, +}: openSubscribePopupType) => { + if (isSubscribePopup) { + getMatchInfo(matchConfig.sportId, matchConfig.matchId) + .then((match: MatchInfo) => { + const matchProfile = match && prepareMatchProfile({ + matchId: matchConfig.matchId, + profile: match, + sportType: matchConfig.sportId, + }) + matchProfile && openBuyMatchPopup(matchProfile) + }) + } +} + +export const isSubscribePopup = checkUrlParams('subscribe') && getAllUrlParams('id').length -- 2.30.2 From 62281019f15290902d6d0db48c45feefdf140c0b Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Thu, 26 Jan 2023 23:06:32 +0700 Subject: [PATCH 3/3] fix(#242): add return to start page with buypoup --- src/features/AuthStore/hooks/useAuth.tsx | 6 +- .../components/PackageSelectionStep/index.tsx | 65 +++++++++++-------- .../components/SelectSubscription/index.tsx | 2 +- src/features/BuyMatchPopup/store/helpers.tsx | 4 +- .../BuyMatchPopup/store/hooks/index.tsx | 6 +- src/features/BuyMatchPopup/styled.tsx | 2 +- .../components/SubscriptionGuard/index.tsx | 6 +- .../getMatchClickAction/__tests__/index.tsx | 14 ++-- .../helpers/getMatchClickAction/index.tsx | 3 +- src/helpers/openSubscribePopup/index.tsx | 4 +- 10 files changed, 66 insertions(+), 46 deletions(-) diff --git a/src/features/AuthStore/hooks/useAuth.tsx b/src/features/AuthStore/hooks/useAuth.tsx index d9b10b6f..4d0a4542 100644 --- a/src/features/AuthStore/hooks/useAuth.tsx +++ b/src/features/AuthStore/hooks/useAuth.tsx @@ -141,7 +141,7 @@ export const useAuth = () => { if (page.includes(PAGES.useraccount)) { history.push(PAGES.home) } else { - const route = `${page}${page === '/' ? search : ''}` + const route = `${page}${search}` history.push(route) } markUserLoaded() @@ -204,11 +204,11 @@ export const useAuth = () => { // ]) useEffect(() => { + // попытаемся обновить токен используя refresh_token const tryRenewToken = () => { userManager.signinSilent() .catch(() => user && logout()) } - // попытаемся обновить токен используя refresh_token // если запросы вернули 401 | 403 window.addEventListener('FORBIDDEN_REQUEST', tryRenewToken) @@ -250,6 +250,7 @@ export const useAuth = () => { loadingUser, login, logout, + setSearch, setUserInfo, user, userInfo, @@ -261,6 +262,7 @@ export const useAuth = () => { userInfo, login, loadingUser, + setSearch, setUserInfo, ]) diff --git a/src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx b/src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx index b7e23456..07149645 100644 --- a/src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx +++ b/src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx @@ -12,8 +12,6 @@ import { MDASH } from 'config' import { payments } from 'config/payments' import { client } from 'config/clients' -import { isSubscribePopup } from 'helpers' - import { CountryCodeType, getCountryCode } from 'requests/getCountryCode' import { CloseButton, HeaderActions } from 'features/PopupComponents' @@ -22,6 +20,7 @@ import { Name } from 'features/Name' import { useCardsStore } from 'features/CardsStore' import { ArrowLoader } from 'features/ArrowLoader' import { Arrow } from 'features/HeaderFilters/components/DateFilter/styled' +import { useAuthStore } from 'features/AuthStore' import { IframePayment } from '../IframePayment' @@ -45,6 +44,11 @@ export const PackageSelectionStep = () => { } = useCardsStore() const [isOpenIframe, setIsOpenIframe] = useState(false) const [countryCode, setCountryCode] = useState(null) + const { + logout, + setSearch, + user, + } = useAuthStore() const { close, @@ -109,32 +113,30 @@ export const PackageSelectionStep = () => { return ( - {!isSubscribePopup - && ( -
- {hasPreviousStep && ( - - - - - - )} - - {hasPreviousStep && selectedSubscription ? ( - - ) : ( - - - {` ${MDASH} `} - - - )} - - - - -
+ +
+ {hasPreviousStep && ( + + + + + + )} + + {hasPreviousStep && selectedSubscription ? ( + + ) : ( + + + {` ${MDASH} `} + + )} + + + + +
{!isIframePayment && } @@ -145,7 +147,14 @@ export const PackageSelectionStep = () => { ) : ( diff --git a/src/features/BuyMatchPopup/components/SelectSubscription/index.tsx b/src/features/BuyMatchPopup/components/SelectSubscription/index.tsx index 66c542db..0457c888 100644 --- a/src/features/BuyMatchPopup/components/SelectSubscription/index.tsx +++ b/src/features/BuyMatchPopup/components/SelectSubscription/index.tsx @@ -57,7 +57,7 @@ export const SelectSubscriptionStep = () => { return (
- {!isSubscribePopup + {!isSubscribePopup() && ( diff --git a/src/features/BuyMatchPopup/store/helpers.tsx b/src/features/BuyMatchPopup/store/helpers.tsx index cf89faef..33480d7d 100644 --- a/src/features/BuyMatchPopup/store/helpers.tsx +++ b/src/features/BuyMatchPopup/store/helpers.tsx @@ -9,6 +9,8 @@ import type { Season, } from 'requests/getSubscriptions' +import { isSubscribePopup } from 'helpers' + import { getName } from 'features/Name' import type { @@ -101,7 +103,7 @@ const transformPackages = ({ [SubscriptionType.Month]: transformByType(SubscriptionType.Month), [SubscriptionType.Year]: transformByType(SubscriptionType.Year), [SubscriptionType.PayPerView]: - payPerView + payPerView && !isSubscribePopup() ? [{ currency: currencySymbols[payPerView.currency_iso], description: { diff --git a/src/features/BuyMatchPopup/store/hooks/index.tsx b/src/features/BuyMatchPopup/store/hooks/index.tsx index 7a30864c..4de6393c 100644 --- a/src/features/BuyMatchPopup/store/hooks/index.tsx +++ b/src/features/BuyMatchPopup/store/hooks/index.tsx @@ -113,6 +113,10 @@ export const useBuyMatchPopup = () => { setError('') resetSubscriptions() setSelectedPackage(null) + + if (isSubscribePopup()) { + history.replace({ search: '' }) + } } const redirectToMatchProfile = ({ id, sportType }: Match) => { @@ -127,7 +131,7 @@ export const useBuyMatchPopup = () => { const onSuccessfulSubscription = () => goTo(Steps.Success) const postPaymentHandler = () => { if (!match) return - if (!isSubscribePopup) { + if (!isSubscribePopup()) { redirectToMatchProfile(match) } closePopup() diff --git a/src/features/BuyMatchPopup/styled.tsx b/src/features/BuyMatchPopup/styled.tsx index 48c6e6c5..3151c037 100644 --- a/src/features/BuyMatchPopup/styled.tsx +++ b/src/features/BuyMatchPopup/styled.tsx @@ -8,7 +8,7 @@ import { Modal as BaseModal } from 'features/Modal' export const Modal = styled(BaseModal)` background-color: rgba(0, 0, 0, 0.7); - + z-index: 52; ${ModalWindow} { padding: 0; background-color: #333333; diff --git a/src/features/MatchPage/components/SubscriptionGuard/index.tsx b/src/features/MatchPage/components/SubscriptionGuard/index.tsx index 9c502d0a..68e8494d 100644 --- a/src/features/MatchPage/components/SubscriptionGuard/index.tsx +++ b/src/features/MatchPage/components/SubscriptionGuard/index.tsx @@ -22,9 +22,9 @@ export const SubscriptionGuard = ({ children }: Props) => { const { user } = useAuthStore() useEffect(() => { - if (user && matchProfile && ( - !matchProfile.sub - || isSubscribePopup)) { + if ((user && matchProfile + && !matchProfile.sub) + || (matchProfile && isSubscribePopup())) { const profile = prepareMatchProfile({ matchId, profile: matchProfile, diff --git a/src/features/Matches/helpers/getMatchClickAction/__tests__/index.tsx b/src/features/Matches/helpers/getMatchClickAction/__tests__/index.tsx index 176f9500..eff2f50c 100644 --- a/src/features/Matches/helpers/getMatchClickAction/__tests__/index.tsx +++ b/src/features/Matches/helpers/getMatchClickAction/__tests__/index.tsx @@ -16,13 +16,15 @@ const createMatch = (args: Args) => ({ ...args, } as Match) +const user = undefined + it('equals to no country access type', () => { const match = createMatch({ access: false, sub: false, }) - expect(getMatchAccess(match)).toBe(MatchAccess.CanBuyMatch) + expect(getMatchAccess(match, user)).toBe(MatchAccess.ViewMatchPopupWithoutUser) }) it('equals to redirect type', () => { @@ -34,7 +36,7 @@ it('equals to redirect type', () => { sub: true, }) - expect(getMatchAccess(match)).toBe(MatchAccess.RedirectToProfile) + expect(getMatchAccess(match, user)).toBe(MatchAccess.ViewMatchPopupWithoutUser) }) it('equals to can buy type', () => { @@ -43,7 +45,7 @@ it('equals to can buy type', () => { sub: false, }) - expect(getMatchAccess(match)).toBe(MatchAccess.CanBuyMatch) + expect(getMatchAccess(match, user)).toBe(MatchAccess.ViewMatchPopupWithoutUser) }) it('equals to view match popup type', () => { @@ -54,7 +56,7 @@ it('equals to view match popup type', () => { sub: true, }) - expect(getMatchAccess(match)).toBe(MatchAccess.ViewMatchPopup) + expect(getMatchAccess(match, user)).toBe(MatchAccess.ViewMatchPopupWithoutUser) match = createMatch({ access: true, @@ -65,7 +67,7 @@ it('equals to view match popup type', () => { sub: true, }) - expect(getMatchAccess(match)).toBe(MatchAccess.RedirectToProfile) + expect(getMatchAccess(match, user)).toBe(MatchAccess.ViewMatchPopupWithoutUser) match = createMatch({ access: true, @@ -77,5 +79,5 @@ it('equals to view match popup type', () => { sub: true, }) - expect(getMatchAccess(match)).toBe(MatchAccess.ViewMatchPopup) + expect(getMatchAccess(match, user)).toBe(MatchAccess.NoAccess) }) diff --git a/src/features/Matches/helpers/getMatchClickAction/index.tsx b/src/features/Matches/helpers/getMatchClickAction/index.tsx index 6f038e27..9a799281 100644 --- a/src/features/Matches/helpers/getMatchClickAction/index.tsx +++ b/src/features/Matches/helpers/getMatchClickAction/index.tsx @@ -2,6 +2,7 @@ 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', @@ -28,7 +29,7 @@ export const getMatchAccess = (match: Match, user: User | undefined) => { switch (true) { case !user && isFutureDate: return MatchAccess.NoAccess - case !user: + case !user && !isSubscribePopup(): return MatchAccess.ViewMatchPopupWithoutUser case !sub: return MatchAccess.CanBuyMatch diff --git a/src/helpers/openSubscribePopup/index.tsx b/src/helpers/openSubscribePopup/index.tsx index 838f8a8d..b00bdda6 100644 --- a/src/helpers/openSubscribePopup/index.tsx +++ b/src/helpers/openSubscribePopup/index.tsx @@ -17,7 +17,7 @@ export const openSubscribePopup = ({ matchConfig, openBuyMatchPopup, }: openSubscribePopupType) => { - if (isSubscribePopup) { + if (isSubscribePopup()) { getMatchInfo(matchConfig.sportId, matchConfig.matchId) .then((match: MatchInfo) => { const matchProfile = match && prepareMatchProfile({ @@ -30,4 +30,4 @@ export const openSubscribePopup = ({ } } -export const isSubscribePopup = checkUrlParams('subscribe') && getAllUrlParams('id').length +export const isSubscribePopup = () => checkUrlParams('subscribe') && getAllUrlParams('id').length -- 2.30.2