diff --git a/src/components/AccessTimer/styled.tsx b/src/components/AccessTimer/styled.tsx index d9beec29..fb2e24c7 100644 --- a/src/components/AccessTimer/styled.tsx +++ b/src/components/AccessTimer/styled.tsx @@ -1,6 +1,6 @@ import styled, { css } from 'styled-components/macro' -import { isMobileDevice } from 'config/userAgent' +import { isMobileDevice } from 'config' import { ButtonSolid } from 'features/Common' diff --git a/src/components/SimplePopup/index.tsx b/src/components/SimplePopup/index.tsx index b07c42ad..1ad02429 100644 --- a/src/components/SimplePopup/index.tsx +++ b/src/components/SimplePopup/index.tsx @@ -1,4 +1,4 @@ -import { ReactNode } from 'react' +import type { ReactNode } from 'react' import { T9n } from 'features/T9n' diff --git a/src/components/SimplePopup/styled.tsx b/src/components/SimplePopup/styled.tsx index a332bd73..832eea4a 100644 --- a/src/components/SimplePopup/styled.tsx +++ b/src/components/SimplePopup/styled.tsx @@ -1,6 +1,6 @@ import styled, { css } from 'styled-components/macro' -import { isMobileDevice } from 'config/userAgent' +import { isMobileDevice } from 'config' import { ModalWindow } from 'features/Modal/styled' import { @@ -9,9 +9,8 @@ import { Modal as BaseModal, HeaderTitle, } from 'features/AuthServiceApp/components/RegisterPopup/styled' - +import { Header as BaseHeader } from 'features/PopupComponents' import { client } from 'features/AuthServiceApp/config/clients/index' -import { Header as BaseHeader } from '../../features/PopupComponents' export const Modal = styled(BaseModal)` @@ -58,7 +57,7 @@ export const ScHeaderTitle = styled(HeaderTitle)` ${isMobileDevice ? css` font-size: 20px; - line-height: 24px; + line-height: 24px; @media screen and (orientation: landscape) { font-size: 17px; @@ -142,9 +141,6 @@ export const Footer = styled.div` ${isMobileDevice ? css` padding-top: 30px; - - @media screen and (orientation: landscape) { - } ` : ''}; ` diff --git a/src/features/App/index.tsx b/src/features/App/index.tsx index a7386b98..3010ffcf 100644 --- a/src/features/App/index.tsx +++ b/src/features/App/index.tsx @@ -12,6 +12,8 @@ import { client } from 'config/clients' import { matomoInstance } from 'config/matomo' import { isAvailable } from 'config/env' +import { readToken } from 'helpers' + import { setClientTitleAndDescription } from 'helpers/setClientHeads' import { GlobalStores } from 'features/GlobalStores' @@ -22,7 +24,6 @@ import { Theme } from 'features/Theme' import { UnavailableText } from 'components/UnavailableText' import { AuthenticatedApp } from './AuthenticatedApp' -import { readToken } from '../../helpers' import { useAuthStore } from '../AuthStore' setClientTitleAndDescription(client.title, client.description) diff --git a/src/features/AuthServiceApp/components/Login/hooks.tsx b/src/features/AuthServiceApp/components/Login/hooks.tsx index 1eb24230..5488400f 100644 --- a/src/features/AuthServiceApp/components/Login/hooks.tsx +++ b/src/features/AuthServiceApp/components/Login/hooks.tsx @@ -16,10 +16,11 @@ import { loginCheck } from 'features/AuthServiceApp/requests/auth' import { getApiUrl } from 'features/AuthServiceApp/config/routes' import { useAuthFields } from 'features/AuthServiceApp/hooks/useAuthFields' +import { addAccessTokenToUrl } from 'helpers/languageUrlParam' + import { AuthProviders } from '../../config/authProviders' import { getAuthUrl } from '../../helpers/getAuthUrl' import { useParamsUrl } from '../../hooks/useParamsUrl' -import { addAccessTokenToUrl } from '../../../../helpers/languageUrlParam' const url = getApiUrl('/authorize') diff --git a/src/features/AuthServiceApp/components/Oauth/hooks.tsx b/src/features/AuthServiceApp/components/Oauth/hooks.tsx index bf02cac9..02cab2d6 100644 --- a/src/features/AuthServiceApp/components/Oauth/hooks.tsx +++ b/src/features/AuthServiceApp/components/Oauth/hooks.tsx @@ -12,7 +12,7 @@ import { isValidEmail } from 'features/AuthServiceApp/helpers/isValidEmail' import { addAccessTokenToUrl } from 'helpers/languageUrlParam' -import { API_ROOT } from '../../config/routes' +import { API_ROOT } from 'config/routes' export const useOauth = () => { const [email, setEmail] = useState('') diff --git a/src/features/AuthServiceApp/components/RegisterPopup/styled.tsx b/src/features/AuthServiceApp/components/RegisterPopup/styled.tsx index 83e06bb0..72782aed 100644 --- a/src/features/AuthServiceApp/components/RegisterPopup/styled.tsx +++ b/src/features/AuthServiceApp/components/RegisterPopup/styled.tsx @@ -6,11 +6,10 @@ import { devices } from 'config/devices' import { ModalWindow } from 'features/Modal/styled' import { Modal as BaseModal } from 'features/Modal' import { Header as BaseHeader } from 'features/PopupComponents' +import { client } from 'features/AuthServiceApp/config/clients' import { ButtonSolid } from 'features/Common' -import { client } from '../../config/clients' - export const Modal = styled(BaseModal)` background-color: rgba(0, 0, 0, 0.7); padding: 0 60px; diff --git a/src/features/AuthServiceApp/requests/register.tsx b/src/features/AuthServiceApp/requests/register.tsx index 9b58ace4..25c4068e 100644 --- a/src/features/AuthServiceApp/requests/register.tsx +++ b/src/features/AuthServiceApp/requests/register.tsx @@ -1,7 +1,8 @@ import type { ClientIds } from 'config/clients/types' +import { checkCookie } from 'helpers/cookie' + import { getApiUrl } from 'features/AuthServiceApp/config/routes' -import { checkCookie } from '../../../helpers/cookie' const errorLexics = { 1: 'error_invalid_email_or_password', diff --git a/src/features/MatchCard/hooks.tsx b/src/features/MatchCard/hooks.tsx index 4187cdfa..2083e3af 100644 --- a/src/features/MatchCard/hooks.tsx +++ b/src/features/MatchCard/hooks.tsx @@ -34,6 +34,9 @@ export const useCard = (match: Match) => { const onMatchClick = useCallback(() => { switch (match.access) { + case MatchAccess.ViewMatchPopupWithoutUser: + redirectToMatchPage() + break case MatchAccess.CanBuyMatch: openBuyMatchPopup(match) break diff --git a/src/features/MatchPage/components/SubscriptionGuard/index.tsx b/src/features/MatchPage/components/SubscriptionGuard/index.tsx index afec2c00..1d2bcac5 100644 --- a/src/features/MatchPage/components/SubscriptionGuard/index.tsx +++ b/src/features/MatchPage/components/SubscriptionGuard/index.tsx @@ -6,9 +6,9 @@ import { usePageParams } from 'hooks/usePageParams' import { useBuyMatchPopupStore } from 'features/BuyMatchPopup' import { useMatchPageStore } from 'features/MatchPage/store' +import { checkUrlParams, getAllUrlParams } from 'helpers/parseUrlParams/parseUrlParams' import { prepareMatchProfile } from '../../helpers/prepareMatchProfile' import { useAuthStore } from '../../../AuthStore' -import { checkUrlParams, getAllUrlParams } from '../../../../helpers/parseUrlParams/parseUrlParams' type Props = { children: ReactNode, @@ -21,8 +21,7 @@ export const SubscriptionGuard = ({ children }: Props) => { const { user } = useAuthStore() useEffect(() => { - if (matchProfile && !matchProfile.sub && !user) { - if (matchProfile && ( + if (user && matchProfile && ( !matchProfile.sub || (checkUrlParams('subscribe') && getAllUrlParams('id')))) { diff --git a/src/features/MatchPage/store/hooks/index.tsx b/src/features/MatchPage/store/hooks/index.tsx index 9ca61451..586a47c3 100644 --- a/src/features/MatchPage/store/hooks/index.tsx +++ b/src/features/MatchPage/store/hooks/index.tsx @@ -9,6 +9,7 @@ import filter from 'lodash/filter' import isEmpty from 'lodash/isEmpty' import { FULL_GAME_KEY } from 'features/MatchPage/helpers/buildPlaylists' +import { useAuthStore } from 'features/AuthStore' import type { MatchInfo } from 'requests/getMatchInfo' import { getMatchInfo } from 'requests/getMatchInfo' @@ -23,7 +24,6 @@ import { useTournamentData } from './useTournamentData' import { useMatchData } from './useMatchData' import { useFiltersPopup } from './useFitersPopup' import { useTabEvents } from './useTabEvents' -import { useAuthStore } from '../../../AuthStore' const ACCESS_TIME = 60 diff --git a/src/features/Matches/helpers/getMatchClickAction/index.tsx b/src/features/Matches/helpers/getMatchClickAction/index.tsx index 1d653b0d..4539f329 100644 --- a/src/features/Matches/helpers/getMatchClickAction/index.tsx +++ b/src/features/Matches/helpers/getMatchClickAction/index.tsx @@ -1,23 +1,29 @@ import type { Match } from 'requests' +import type { User } from 'oidc-client' + export enum MatchAccess { CanBuyMatch = 'CanBuyMatch', NoAccess = 'NoAccess', NoCountryAccess = 'NoCountryAccess', RedirectToProfile = 'RedirectToProfile', ViewMatchPopup = 'ViewMatchPopup', + ViewMatchPopupWithoutUser = 'ViewMatchPopupWithoutUser', } -export const getMatchAccess = ({ - access, - date, - live, - sub, -}: Match) => { +export const getMatchAccess = (match: Match, user: User | undefined) => { + const { + access, + date, + live, + sub, + } = match const dateToMs = Date.parse(date?.replace(/ /, 'T')) // без замены не будет работать в сафари const dateNowMin10 = dateToMs - 10 * 60 * 1000 switch (true) { + case !user: + return MatchAccess.ViewMatchPopupWithoutUser case !sub: return MatchAccess.CanBuyMatch case !access: diff --git a/src/features/Matches/helpers/prepareMatches.tsx b/src/features/Matches/helpers/prepareMatches.tsx index f218cd87..bec2581b 100644 --- a/src/features/Matches/helpers/prepareMatches.tsx +++ b/src/features/Matches/helpers/prepareMatches.tsx @@ -2,13 +2,15 @@ import map from 'lodash/map' import orderBy from 'lodash/orderBy' import format from 'date-fns/format' +import type { User } from 'oidc-client' + import type { Match } from 'requests' import { parseDate } from 'helpers/parseDate' import { getMatchAccess } from './getMatchClickAction' -const prepareMatch = (match: Match) => { +const prepareMatch = (match: Match, user?: User | undefined) => { const { calc, country, @@ -31,7 +33,7 @@ const prepareMatch = (match: Match) => { const date = parseDate(matchDate) return { - access: getMatchAccess(match), + access: getMatchAccess(match, user), calc, countryId: country_id, countryInfo: country, @@ -54,10 +56,10 @@ const prepareMatch = (match: Match) => { } } -export const prepareMatches = (matches: Array) => { +export const prepareMatches = (matches: Array, user?: User | undefined) => { const preparedMatches = map( matches, - prepareMatch, + (match) => prepareMatch(match, user), ) return orderBy( preparedMatches, diff --git a/src/features/Matches/hooks.tsx b/src/features/Matches/hooks.tsx index 2235bb4e..ec59b014 100644 --- a/src/features/Matches/hooks.tsx +++ b/src/features/Matches/hooks.tsx @@ -15,6 +15,8 @@ import { isMobileDevice } from 'config/userAgent' import { prepareMatches } from './helpers/prepareMatches' +import { useAuthStore } from '../AuthStore' + export type Match = ReturnType[number] export type Props = { @@ -33,6 +35,7 @@ const initialState = { export const useMatches = ({ fetch }: Props) => { const { userPreferences } = usePreferencesStore() + const { user } = useAuthStore() const { isFetching, request: requestMatches, @@ -81,10 +84,11 @@ export const useMatches = ({ fetch }: Props) => { }, [fetchMatches, userPreferences]) const preparedMatches = useMemo(() => ({ - broadcast: prepareMatches(matches.broadcast), - features: prepareMatches(matches.features), - highlights: prepareMatches(matches.highlights), + broadcast: prepareMatches(matches.broadcast, user), + features: prepareMatches(matches.features, user), + highlights: prepareMatches(matches.highlights, user), isVideoSections: matches.isVideoSections, + // eslint-disable-next-line react-hooks/exhaustive-deps }), [matches]) return { diff --git a/src/features/Menu/index.tsx b/src/features/Menu/index.tsx index 7d1bc684..e6413b04 100644 --- a/src/features/Menu/index.tsx +++ b/src/features/Menu/index.tsx @@ -6,6 +6,8 @@ import { PAGES } from 'config/pages' import { usePreferencesStore } from 'features/PreferencesPopup' import { useTournamentPopupStore } from 'features/TournamentsPopup/store' +import { useAuthStore } from 'features/AuthStore' + import { FavoritesMobilePopup } from '../FavoritesMobilePopup' import { @@ -14,8 +16,6 @@ import { Icon, } from './styled' -import { useAuthStore } from '../AuthStore' - export const Menu = () => { const { openPopup } = usePreferencesStore() const { open } = useTournamentPopupStore() diff --git a/src/features/MultiSourcePlayer/index.tsx b/src/features/MultiSourcePlayer/index.tsx index d000d909..e3883583 100644 --- a/src/features/MultiSourcePlayer/index.tsx +++ b/src/features/MultiSourcePlayer/index.tsx @@ -14,15 +14,16 @@ import { Controls } from 'features/StreamPlayer/components/Controls' import { Name } from 'features/Name' import RewindMobile from 'features/StreamPlayer/components/RewindMobile' import { FiltersPopup } from 'features/MatchSidePlaylists/components/FiltersPopup' +import { useAuthStore } from 'features/AuthStore' import { isMobileDevice } from 'config/userAgent' +import { AccessTimer } from 'components/AccessTimer' + import type { Props } from './hooks' import { useMultiSourcePlayer } from './hooks' import { Players } from './types' import { REWIND_SECONDS } from './config' -import { AccessTimer } from '../../components/AccessTimer' -import { useAuthStore } from '../AuthStore' export const MultiSourcePlayer = (props: Props) => { const { diff --git a/src/features/StreamPlayer/index.tsx b/src/features/StreamPlayer/index.tsx index 261f4c01..a91a03c5 100644 --- a/src/features/StreamPlayer/index.tsx +++ b/src/features/StreamPlayer/index.tsx @@ -5,6 +5,7 @@ import { Name } from 'features/Name' import { FiltersPopup } from 'features/MatchSidePlaylists/components/FiltersPopup' import { WaterMark } from 'components/WaterMark' +import { AccessTimer } from 'components/AccessTimer' import { isMobileDevice } from 'config/userAgent' @@ -25,7 +26,6 @@ import { useVideoPlayer } from './hooks' import { useAuthStore } from '../AuthStore' import { Controls } from './components/Controls' import RewindMobile from './components/RewindMobile' -import { AccessTimer } from '../../components/AccessTimer' /** * HLS плеер, применяется на лайв и завершенных матчах diff --git a/src/features/TournamentPage/hooks.tsx b/src/features/TournamentPage/hooks.tsx index 093c61e2..bc2ec773 100644 --- a/src/features/TournamentPage/hooks.tsx +++ b/src/features/TournamentPage/hooks.tsx @@ -18,9 +18,10 @@ 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 { useAuthStore } from '../AuthStore' import { useBuyMatchPopupStore } from '../BuyMatchPopup' import { MATCH_CONFIG } from '../BuyMatchPopup/store/hooks/useSubscriptions' import { prepareMatchProfile } from '../MatchPage/helpers/prepareMatchProfile' diff --git a/src/requests/getTokenVirtualUser.tsx b/src/requests/getTokenVirtualUser.tsx index 5920aaeb..fd5b5b0f 100644 --- a/src/requests/getTokenVirtualUser.tsx +++ b/src/requests/getTokenVirtualUser.tsx @@ -1,5 +1,6 @@ import { AUTH_SERVICE } from '../config/routes' import { client } from '../config/clients' +import { callApi } from '../helpers' export const getTokenVirtualUser = async () => { const url = `${AUTH_SERVICE}/v1/user/create?client_id=${client.auth.clientId}` @@ -8,9 +9,5 @@ export const getTokenVirtualUser = async () => { method: 'POST', } - const response = await fetch(url, config) - - const body = await response.json() - - return body + return callApi({ config, url }) }