fix(#2592): fix logic for disable button in popup payment

keep-around/32d01affbea7fe6359a08e9406ef2656eec49f08
Andrei Dekterev 3 years ago
parent 1e28a34fbd
commit 32d01affbe
  1. 12
      src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx
  2. 3
      src/features/BuyMatchPopup/store/hooks/index.tsx

@ -33,7 +33,10 @@ import {
} from '../../styled' } from '../../styled'
export const PackageSelectionStep = () => { export const PackageSelectionStep = () => {
const { cards, fetchCards } = useCardsStore() const {
cards,
fetchCards,
} = useCardsStore()
const [isOpenBrasilian, setIsOpenBrasilian] = useState(false) const [isOpenBrasilian, setIsOpenBrasilian] = useState(false)
const { user } = useAuthStore() const { user } = useAuthStore()
@ -42,12 +45,14 @@ export const PackageSelectionStep = () => {
disabledBuyBtn, disabledBuyBtn,
goBack, goBack,
hasPreviousStep, hasPreviousStep,
lastSelectedPackage,
loader, loader,
match, match,
onBuyClick, onBuyClick,
selectedPackage, selectedPackage,
selectedSubscription, selectedSubscription,
setDisabledBuyBtn, setDisabledBuyBtn,
setLastSelectedPackage,
} = useBuyMatchPopupStore() } = useBuyMatchPopupStore()
useEffect(() => { useEffect(() => {
@ -61,12 +66,15 @@ export const PackageSelectionStep = () => {
const isBrasil = user?.profile.country_code === 'BR' const isBrasil = user?.profile.country_code === 'BR'
const onHandleClick = (e?: MouseEvent<HTMLButtonElement>) => { const onHandleClick = (e?: MouseEvent<HTMLButtonElement>) => {
setDisabledBuyBtn(true) cards?.length
&& lastSelectedPackage === selectedPackage?.id
&& setDisabledBuyBtn(true)
if (isBrasil) { if (isBrasil) {
setIsOpenBrasilian(true) setIsOpenBrasilian(true)
} else { } else {
onBuyClick(e) onBuyClick(e)
} }
setLastSelectedPackage(selectedPackage?.id || '')
} }
return ( return (

@ -53,6 +53,7 @@ export const useBuyMatchPopup = () => {
const [error, setError] = useState('') const [error, setError] = useState('')
const [loader, setLoader] = useState(false) const [loader, setLoader] = useState(false)
const [disabledBuyBtn, setDisabledBuyBtn] = useState(false) const [disabledBuyBtn, setDisabledBuyBtn] = useState(false)
const [lastSelectedPackage, setLastSelectedPackage] = useState('')
const setDataHighlights = useSetRecoilState(dataForPayHighlights) const setDataHighlights = useSetRecoilState(dataForPayHighlights)
const goTo = useCallback( const goTo = useCallback(
@ -205,6 +206,7 @@ export const useBuyMatchPopup = () => {
goBack, goBack,
goTo, goTo,
hasPreviousStep: size(steps) > 1, hasPreviousStep: size(steps) > 1,
lastSelectedPackage,
loader, loader,
match, match,
matchSubscriptions, matchSubscriptions,
@ -223,6 +225,7 @@ export const useBuyMatchPopup = () => {
selectedPeriod, selectedPeriod,
selectedSubscription, selectedSubscription,
setDisabledBuyBtn, setDisabledBuyBtn,
setLastSelectedPackage,
subscriptions, subscriptions,
} }
} }

Loading…
Cancel
Save