fix(#2445): add redirect to matchpage for brasil payment after pay

keep-around/43461da6ad25c0cf2fbd30db2528ee5224336eaf
Andrei Dekterev 4 years ago
parent b13bf04926
commit 1870f2c963
  1. 78
      src/features/BuyMatchPopup/components/BrazilPayment/hooks.tsx
  2. 54
      src/features/BuyMatchPopup/components/BrazilPayment/index.tsx
  3. 1
      src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx
  4. 1
      src/requests/getMatchInfo.tsx

@ -0,0 +1,78 @@
import {
useEffect,
useState,
MouseEvent,
} from 'react'
import { useHistory } from 'react-router-dom'
import { ProfileTypes } from 'config'
import isNumber from 'lodash/isNumber'
import { useLexicsStore } from 'features/LexicsStore'
import { getProfileUrl } from 'features/ProfileLink/helpers'
import { getMatchInfo } from 'requests/getMatchInfo'
import { getBrazilPaymentUrl } from 'requests/getBrazilPaymentUrl'
import type { Props } from './index'
type ResponsePayment = {
url: string,
}
type ResponsePaymentArray = ResponsePayment | null
export const useBrazilPayment = ({
match,
open,
selectedPackage,
setIsOpenBrasilian,
}: Props) => {
const history = useHistory()
const [src, setSrc] = useState('')
const { translate } = useLexicsStore()
const {
name,
nameLexic,
originalObject,
pass,
} = selectedPackage
const teams = isNumber(nameLexic) ? translate(String(nameLexic)) : name
const pack = translate(String(pass))
const closePopup = async (e?: MouseEvent) => {
e?.stopPropagation()
setIsOpenBrasilian(false)
const { id, sportType } = match
const accessMatch = await getMatchInfo(sportType, id)
if (accessMatch?.access) {
const matchLink = getProfileUrl({
id,
profileType: ProfileTypes.MATCHES,
sportType,
})
history.push(matchLink)
}
}
useEffect(() => {
if (open) {
(async () => {
const json: ResponsePaymentArray = await getBrazilPaymentUrl({ item: originalObject, product_name: `${pack} ${teams}` })
setSrc(json?.url || '')
})()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedPackage, open])
return {
closePopup,
src,
}
}

@ -1,61 +1,29 @@
import {
useEffect,
useState,
MouseEvent,
} from 'react'
import { Loader } from 'features/Loader'
import { useLexicsStore } from 'features/LexicsStore'
import { MatchPackage } from 'features/BuyMatchPopup/types'
import { getBrazilPaymentUrl } from 'requests/getBrazilPaymentUrl'
import { MatchPackage, Match } from 'features/BuyMatchPopup/types'
import isNumber from 'lodash/isNumber'
import { useBrazilPayment } from './hooks'
import { ScModal, LoaderWrapper } from './styled'
type Props = {
export type Props = {
match: Match,
open: boolean,
selectedPackage: MatchPackage,
setIsOpenBrasilian: (open: boolean) => void,
}
type ResponsePayment = {
url: string,
}
type ResponsePaymentArray = ResponsePayment | null
export const BrazilPayment = ({
match,
open,
selectedPackage,
setIsOpenBrasilian,
}: Props) => {
const {
name,
nameLexic,
originalObject,
pass,
} = selectedPackage
const [src, setSrc] = useState('')
const { translate } = useLexicsStore()
const teams = isNumber(nameLexic) ? translate(String(nameLexic)) : name
const pack = translate(String(pass))
const closePopup = (e?: MouseEvent) => {
e?.stopPropagation()
setIsOpenBrasilian(false)
}
useEffect(() => {
if (open) {
(async () => {
const json: ResponsePaymentArray = await getBrazilPaymentUrl({ item: originalObject, product_name: `${pack} ${teams}` })
setSrc(json?.url || '')
})()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedPackage, open])
const { closePopup, src } = useBrazilPayment({
match,
open,
selectedPackage,
setIsOpenBrasilian,
})
return (
<ScModal isOpen={open} withCloseButton close={closePopup}>

@ -109,6 +109,7 @@ export const PackageSelectionStep = () => {
</Footer>
{selectedPackage && isOpenBrasilian && (
<BrazilPayment
match={match}
open={isOpenBrasilian}
selectedPackage={selectedPackage}
setIsOpenBrasilian={setIsOpenBrasilian}

@ -17,6 +17,7 @@ export type Team = {
}
export type MatchInfo = {
access?: boolean,
calc: boolean,
country_id: number,
date: string,

Loading…
Cancel
Save