Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(animatedcheckbox): Save Card Details checkbox changes #184

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/Payments/CardPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,20 @@ let make = (
React.useEffect1(() => {
switch customerPaymentMethods {
| LoadingSavedCards => ()
| LoadedSavedCards(arr) => {
| LoadedSavedCards(arr, isGuestCustomer) => {
let savedCards = arr->Js.Array2.filter((item: PaymentType.customerMethods) => {
item.paymentMethod == "card"
})
setSavedMethods(_ => savedCards)
setLoadSavedCards(_ =>
savedCards->Js.Array2.length == 0 ? NoResult : LoadedSavedCards(savedCards)
savedCards->Js.Array2.length == 0
? NoResult(isGuestCustomer)
: LoadedSavedCards(savedCards, isGuestCustomer)
)
setShowFields(.prev => savedCards->Js.Array2.length == 0 || prev)
}
| NoResult => {
setLoadSavedCards(_ => NoResult)
| NoResult(isGuestCustomer) => {
setLoadSavedCards(_ => NoResult(isGuestCustomer))
setShowFields(._ => true)
}
}
Expand All @@ -105,7 +107,7 @@ let make = (
React.useEffect1(() => {
if disableSaveCards {
setShowFields(._ => true)
setLoadSavedCards(_ => LoadedSavedCards([]))
setLoadSavedCards(_ => LoadedSavedCards([], true))
}
None
}, [disableSaveCards])
Expand Down Expand Up @@ -140,6 +142,14 @@ let make = (
None
}, (empty, complete))

let isGuestCustomer = React.useMemo1(() => {
switch customerPaymentMethods {
| LoadedSavedCards(_, false)
| NoResult(false) => false
| _ => true
}
}, [customerPaymentMethods])

let isCvcValidValue = CardUtils.getBoolOptionVal(isCVCValid)
let (cardEmpty, cardComplete, cardInvalid) = CardUtils.useCardDetails(
~cvcNumber,
Expand Down Expand Up @@ -326,7 +336,7 @@ let make = (
cvcProps={Some(cvcProps)}
isBancontact
/>
<RenderIf condition={!isBancontact && !options.disableSaveCards}>
<RenderIf condition={!isBancontact && !options.disableSaveCards && !isGuestCustomer}>
<div className="pt-4 pb-2 flex items-center justify-start">
<AnimatedCheckbox isChecked=isSaveCardsChecked setIsChecked=setIsSaveCardsChecked />
</div>
Expand Down
15 changes: 11 additions & 4 deletions src/Types/PaymentType.res
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ type customerMethods = {
paymentMethodIssuer: option<string>,
card: customerCard,
}
type savedCardsLoadState = LoadingSavedCards | LoadedSavedCards(array<customerMethods>) | NoResult
type savedCardsLoadState =
LoadingSavedCards | LoadedSavedCards(array<customerMethods>, bool) | NoResult(bool)

prafulkoppalkar marked this conversation as resolved.
Show resolved Hide resolved
type billingAddress = {
isUseBillingAddress: bool,
Expand Down Expand Up @@ -247,7 +248,7 @@ let defaultBillingAddress = {
let defaultOptions = {
defaultValues: defaultDefaultValues,
business: defaultBusiness,
customerPaymentMethods: NoResult,
customerPaymentMethods: NoResult(true),
layout: ObjectLayout(defaultLayout),
paymentMethodOrder: None,
fields: defaultFields,
Expand Down Expand Up @@ -777,6 +778,12 @@ let createCustomerObjArr = dict => {
->Belt.Option.flatMap(Js.Json.decodeArray)
->Belt.Option.getWithDefault([])

let isGuestCustomer =
customerDict
->Js.Dict.get("is_guest_customer")
->Belt.Option.flatMap(Js.Json.decodeBoolean)
->Belt.Option.getWithDefault(false)

let customerPaymentMethods =
customerArr
->Belt.Array.keepMap(Js.Json.decodeObject)
Expand All @@ -789,7 +796,7 @@ let createCustomerObjArr = dict => {
card: getCardDetails(json, "card"),
}
})
LoadedSavedCards(customerPaymentMethods)
LoadedSavedCards(customerPaymentMethods, isGuestCustomer)
}

let getCustomerMethods = (dict, str) => {
Expand All @@ -809,7 +816,7 @@ let getCustomerMethods = (dict, str) => {
card: getCardDetails(json, "card"),
}
})
LoadedSavedCards(customerPaymentMethods)
LoadedSavedCards(customerPaymentMethods, false)
} else {
LoadingSavedCards
}
Expand Down