fix(#2445): add redirect to matchpage for brasil payment after pay
parent
b13bf04926
commit
1870f2c963
@ -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, |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue