Skip to content

Commit

Permalink
fix: comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja committed Apr 16, 2024
1 parent 9baddd0 commit 42365f7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 27 deletions.
26 changes: 14 additions & 12 deletions src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open CardUtils
open Utils
@react.component
let make = (
~paymentToken,
Expand All @@ -10,6 +8,10 @@ let make = (
~paymentType,
~list: PaymentMethodsRecord.list,
) => {
open CardUtils
open Utils
open UtilityHooks

let {themeObj, localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let (showFields, setShowFields) = Recoil.useRecoilState(RecoilAtoms.showCardFieldsAtom)
let areRequiredFieldsValid = Recoil.useRecoilValueFromAtom(RecoilAtoms.areRequiredFieldsValid)
Expand All @@ -21,7 +23,7 @@ let make = (
}
let (isSaveCardsChecked, setIsSaveCardsChecked) = React.useState(_ => false)
let {displaySavedPaymentMethodsCheckbox} = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom)
let isGuestCustomer = UtilityHooks.useIsGuestCustomer()
let isGuestCustomer = useIsGuestCustomer()

let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), Card)
let (token, _) = paymentToken
Expand All @@ -36,13 +38,12 @@ let make = (
}
}

let isCustomerAcceptanceRequired = React.useMemo(() => {
if displaySavedPaymentMethodsCheckbox {
isSaveCardsChecked || list.payment_type === SETUP_MANDATE
} else {
!(isGuestCustomer || list.payment_type === NORMAL)
}
}, (isSaveCardsChecked, list.payment_type))
let isCustomerAcceptanceRequired = useIsCustomerAcceptanceRequired(
~displaySavedPaymentMethodsCheckbox,
~isSaveCardsChecked,
~list,
~isGuestCustomer,
)

let bottomElement = {
savedMethods
Expand Down Expand Up @@ -101,7 +102,7 @@ let make = (

let paymentType = customerMethod.paymentMethodType->Option.getOr(customerMethod.paymentMethod)

UtilityHooks.useHandlePostMessages(~complete, ~empty, ~paymentType, ~savedMethod=true)
useHandlePostMessages(~complete, ~empty, ~paymentType, ~savedMethod=true)

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
Expand Down Expand Up @@ -176,8 +177,9 @@ let make = (
))
useSubmitPaymentData(submitCallback)

let conditionsForShowingSaveCardCheckbox =
let conditionsForShowingSaveCardCheckbox = React.useMemo(() => {
!isGuestCustomer && list.payment_type !== SETUP_MANDATE && displaySavedPaymentMethodsCheckbox
}, (isGuestCustomer, list, displaySavedPaymentMethodsCheckbox))

<div className="flex flex-col overflow-auto h-auto no-scrollbar animate-slowShow">
{if savedCardlength === 0 && (loadSavedCards === PaymentType.LoadingSavedCards || !showFields) {
Expand Down
13 changes: 13 additions & 0 deletions src/Hooks/UtilityHooks.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ let useHandlePostMessages = (~complete, ~empty, ~paymentType, ~savedMethod=false
None
}, (complete, empty, paymentType))
}

let useIsCustomerAcceptanceRequired = (
~displaySavedPaymentMethodsCheckbox,
~isSaveCardsChecked,
~list: PaymentMethodsRecord.list,
~isGuestCustomer,
) => React.useMemo(() => {
if displaySavedPaymentMethodsCheckbox {
isSaveCardsChecked || list.payment_type === SETUP_MANDATE
} else {
!(isGuestCustomer || list.payment_type === NORMAL)
}
}, (isSaveCardsChecked, list.payment_type))
27 changes: 12 additions & 15 deletions src/Payments/CardPayment.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
type target = {checked: bool}
type event = {target: target}
open PaymentType
open PaymentModeType

@react.component
let make = (
Expand All @@ -12,7 +10,11 @@ let make = (
~paymentType: CardThemeType.mode,
~list: PaymentMethodsRecord.list,
) => {
open PaymentType
open PaymentModeType
open Utils
open UtilityHooks

let {config, themeObj, localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let options = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom)
let loggerState = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom)
Expand Down Expand Up @@ -81,27 +83,22 @@ let make = (
None
}, [complete])

UtilityHooks.useHandlePostMessages(
~complete=complete && areRequiredFieldsValid,
~empty,
~paymentType="card",
)
useHandlePostMessages(~complete=complete && areRequiredFieldsValid, ~empty, ~paymentType="card")

let isGuestCustomer = UtilityHooks.useIsGuestCustomer()
let isGuestCustomer = useIsGuestCustomer()
let isCvcValidValue = CardUtils.getBoolOptionVal(isCVCValid)
let (cardEmpty, cardComplete, cardInvalid) = CardUtils.useCardDetails(
~cvcNumber,
~isCVCValid,
~isCvcValidValue,
)

let isCustomerAcceptanceRequired = React.useMemo(() => {
if displaySavedPaymentMethodsCheckbox {
isSaveCardsChecked || list.payment_type === SETUP_MANDATE
} else {
!(isGuestCustomer || list.payment_type === NORMAL)
}
}, (isSaveCardsChecked, list.payment_type))
let isCustomerAcceptanceRequired = useIsCustomerAcceptanceRequired(
~displaySavedPaymentMethodsCheckbox,
~isSaveCardsChecked,
~list,
~isGuestCustomer,
)

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
Expand Down
1 change: 1 addition & 0 deletions src/Utilities/PaymentBody.res
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ let savedPaymentMethodBody = (

savedPaymentMethodBody
}

let savedCardBody = (
~paymentToken,
~customerId,
Expand Down

0 comments on commit 42365f7

Please sign in to comment.