From bf7a50518d74a5cd0d5e74b420d49d5320b515d0 Mon Sep 17 00:00:00 2001 From: sakksham7 <130480324+sakksham7@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:10:32 +0530 Subject: [PATCH 01/13] feat: sdk pay now button enable prop added (#543) Co-authored-by: Saksham Sharma Co-authored-by: Pritish Budhiraja --- src/Components/PayNowButton.res | 5 ++ src/Hooks/UtilityHooks.res | 13 +++- src/TabCard.res | 3 +- src/Types/PaymentType.res | 3 + src/Utilities/Utils.res | 6 +- src/orca-loader/Elements.res | 2 +- src/orca-loader/Hyper.res | 93 ++++++++++++------------ src/orca-loader/LoaderPaymentElement.res | 5 +- 8 files changed, 74 insertions(+), 56 deletions(-) diff --git a/src/Components/PayNowButton.res b/src/Components/PayNowButton.res index fce5de0a4..5c043baff 100644 --- a/src/Components/PayNowButton.res +++ b/src/Components/PayNowButton.res @@ -21,6 +21,11 @@ let make = () => { let confirmPayload = sdkHandleConfirmPayment->PaymentBody.confirmPayloadForSDKButton let buttonText = sdkHandleConfirmPayment.buttonText->Option.getOr(localeString.payNowButton) + React.useEffect1(() => { + setIsPayNowButtonDisable(_ => !sdkHandleConfirmPayment.allowButtonBeforeValidation) + None + }, [sdkHandleConfirmPayment.allowButtonBeforeValidation]) + let handleMessage = (event: Types.event) => { let json = event.data->Identity.anyTypeToJson->getStringFromJson("")->safeParse let dict = json->getDictFromJson diff --git a/src/Hooks/UtilityHooks.res b/src/Hooks/UtilityHooks.res index b75bc6dc6..722000f08 100644 --- a/src/Hooks/UtilityHooks.res +++ b/src/Hooks/UtilityHooks.res @@ -11,12 +11,17 @@ let useIsGuestCustomer = () => { } let useHandlePostMessages = (~complete, ~empty, ~paymentType, ~savedMethod=false) => { - let loggerState = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom) - let setIsPayNowButtonDisable = RecoilAtoms.payNowButtonDisable->Recoil.useSetRecoilState + open RecoilAtoms + + let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom) + let setIsPayNowButtonDisable = Recoil.useSetRecoilState(payNowButtonDisable) + let {sdkHandleConfirmPayment} = Recoil.useRecoilValueFromAtom(optionAtom) React.useEffect(() => { - let isCompletelyFilled = complete && paymentType !== "" - setIsPayNowButtonDisable(_ => !isCompletelyFilled) + if !sdkHandleConfirmPayment.allowButtonBeforeValidation { + let isCompletelyFilled = complete && paymentType !== "" + setIsPayNowButtonDisable(_ => !isCompletelyFilled) + } Utils.handlePostMessageEvents(~complete, ~empty, ~paymentType, ~loggerState, ~savedMethod) None }, (complete, empty, paymentType)) diff --git a/src/TabCard.res b/src/TabCard.res index e0e1ead62..4d1dd7217 100644 --- a/src/TabCard.res +++ b/src/TabCard.res @@ -4,6 +4,7 @@ let make = (~paymentOption: PaymentMethodsRecord.paymentFieldsInfo, ~isActive: b let {themeObj, localeString} = Recoil.useRecoilValueFromAtom(configAtom) let {readOnly, customMethodNames} = Recoil.useRecoilValueFromAtom(optionAtom) let setSelectedOption = Recoil.useSetRecoilState(selectedOptionAtom) + let {sdkHandleConfirmPayment} = optionAtom->Recoil.useRecoilValueFromAtom let setIsPayNowButtonDisable = Recoil.useSetRecoilState(payNowButtonDisable) let (tabClass, tabLabelClass, tabIconClass) = React.useMemo( () => isActive ? ("Tab--selected", "TabLabel--selected", "TabIcon--selected") : ("", "", ""), @@ -16,7 +17,7 @@ let make = (~paymentOption: PaymentMethodsRecord.paymentFieldsInfo, ~isActive: b paymentOption.icon, ) let onClick = _ => { - setIsPayNowButtonDisable(_ => true) + setIsPayNowButtonDisable(_ => !sdkHandleConfirmPayment.allowButtonBeforeValidation) setSelectedOption(_ => paymentOption.paymentMethodName) }