Skip to content

Commit

Permalink
refactor: minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Saksham Sharma authored and Saksham Sharma committed Aug 20, 2024
1 parent fd967b2 commit 64c2e6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Components/PayNowButton.res
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let make = () => {
let (showLoader, setShowLoader) = React.useState(() => false)
let {themeObj, localeString} = configAtom->Recoil.useRecoilValueFromAtom
let {sdkHandleConfirmPayment} = optionAtom->Recoil.useRecoilValueFromAtom
let (isPayNowButtonDisable, setIsPayNowButtonDisable) = payNowButtonDisable->Recoil.useRecoilState

let confirmPayload = sdkHandleConfirmPayment->PaymentBody.confirmPayloadForSDKButton
let buttonText = sdkHandleConfirmPayment.buttonText->Option.getOr(localeString.payNowButton)
Expand All @@ -27,28 +28,31 @@ let make = () => {
switch dict->Dict.get("submitSuccessful") {
| Some(submitSuccessfulVal) =>
if !(submitSuccessfulVal->JSON.Decode.bool->Option.getOr(false)) {
setIsPayNowButtonDisable(_ => false)
setShowLoader(_ => false)
}
| None => ()
}
}

let handleOnClick = _ => {
setIsPayNowButtonDisable(_ => true)
setShowLoader(_ => true)
EventListenerManager.addSmartEventListener("message", handleMessage, "onSubmitSuccessful")
handlePostMessage([("handleSdkConfirm", confirmPayload)])
}

<div className="flex flex-col gap-1 h-auto w-full items-center">
<button
disabled=isPayNowButtonDisable
onClick=handleOnClick
className={`w-full flex flex-row justify-center items-center`}
style={
borderRadius: themeObj.buttonBorderRadius,
backgroundColor: themeObj.buttonBackgroundColor,
height: themeObj.buttonHeight,
cursor: "pointer",
opacity: "1",
cursor: {isPayNowButtonDisable ? "not-allowed" : "pointer"},
opacity: {isPayNowButtonDisable ? "0.6" : "1"},
width: themeObj.buttonWidth,
border: `${themeObj.buttonBorderWidth} solid ${themeObj.buttonBorderColor}`,
}>
Expand Down
1 change: 1 addition & 0 deletions src/Utilities/RecoilAtoms.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let paymentTokenAtom = Recoil.atom(
let showCardFieldsAtom = Recoil.atom("showCardFields", false)
let phoneJson = Recoil.atom("phoneJson", Loading)
let cardBrand = Recoil.atom("cardBrand", "")
let payNowButtonDisable = Recoil.atom("payNowButtonDisable", false)
let paymentMethodCollectOptionAtom = Recoil.atom(
"paymentMethodCollectOptions",
PaymentMethodCollectUtils.defaultPaymentMethodCollectOptions,
Expand Down

0 comments on commit 64c2e6a

Please sign in to comment.