Skip to content

Commit

Permalink
fix:HS:132: Country if prefilled will be taken as such and not from c…
Browse files Browse the repository at this point in the history
…lient timezone (#77)

Co-authored-by: arun.mishra <[email protected]>
  • Loading branch information
arun-mi and arun.mishra authored Dec 21, 2023
1 parent d5e9c82 commit 729bf3c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 46 deletions.
9 changes: 3 additions & 6 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ let make = (
}

React.useEffect0(() => {
let clientTimeZone = Utils.dateTimeFormat(.).resolvedOptions(.).timeZone
let clientCountry = Utils.getClientCountry(clientTimeZone)
setCountry(_ => clientCountry.countryName)
let bank = bankNames->Belt.Array.get(0)->Belt.Option.getWithDefault("")
setSelectedBank(_ => bank)
None
Expand Down Expand Up @@ -346,13 +343,13 @@ let make = (
| BillingName => setFields(setBillingName, billingName, requiredField, true)
| Country
| AddressCountry(_) =>
if value !== "" && country === "" {
let countryCode =
if value !== "" {
let defaultCountry =
Country.getCountry(paymentMethodType)
->Js.Array2.filter(item => item.isoAlpha2 === value)
->Belt.Array.get(0)
->Belt.Option.getWithDefault(Country.defaultTimeZone)
setCountry(_ => countryCode.countryName)
setCountry(_ => defaultCountry.countryName)
}
| Currency(_) =>
if value !== "" && currency === "" {
Expand Down
81 changes: 41 additions & 40 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,42 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
let setUserAddressCountry = Recoil.useLoggedSetRecoilState(userAddressCountry, "country", logger)
let (_country, setCountry) = Recoil.useRecoilState(userCountry)

let optionsCallback = (optionsPayment: PaymentType.options) => {
[
(optionsPayment.defaultValues.billingDetails.name, setUserFullName),
(optionsPayment.defaultValues.billingDetails.email, setUserEmail),
(optionsPayment.defaultValues.billingDetails.address.line1, setUserAddressline1),
(optionsPayment.defaultValues.billingDetails.address.line2, setUserAddressline2),
(optionsPayment.defaultValues.billingDetails.address.city, setUserAddressCity),
(optionsPayment.defaultValues.billingDetails.address.postal_code, setUserAddressPincode),
(optionsPayment.defaultValues.billingDetails.address.state, setUserAddressState),
(optionsPayment.defaultValues.billingDetails.address.country, setUserAddressCountry),
]->Js.Array2.forEach(val => {
let (value, setValue) = val
if value != "" {
setValue(.prev => {
...prev,
value,
})
}
})
if optionsPayment.defaultValues.billingDetails.address.country === "" {
let clientTimeZone = CardUtils.dateTimeFormat(.).resolvedOptions(.).timeZone
let clientCountry = Utils.getClientCountry(clientTimeZone)
setUserAddressCountry(.prev => {
...prev,
value: clientCountry.countryName,
})
setCountry(._ => clientCountry.countryName)
} else {
setUserAddressCountry(.prev => {
...prev,
value: optionsPayment.defaultValues.billingDetails.address.country,
})
setCountry(._ => optionsPayment.defaultValues.billingDetails.address.country)
}
}

let updateOptions = dict => {
let optionsDict = dict->getDictFromObj("options")
switch paymentMode->CardTheme.getPaymentMode {
Expand All @@ -42,7 +78,11 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
| CardCVCElement
| Card =>
setOptions(._ => ElementType.itemToObjMapper(optionsDict, logger))
| Payment => setOptionsPayment(._ => PaymentType.itemToObjMapper(optionsDict, logger))
| Payment => {
let paymentOptions = PaymentType.itemToObjMapper(optionsDict, logger)
setOptionsPayment(._ => paymentOptions)
optionsCallback(paymentOptions)
}
| _ => ()
}
}
Expand Down Expand Up @@ -314,45 +354,6 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
handleMessage(handleFun, "Error in parsing sent Data")
}, (showCardFormByDefault, paymentMethodOrder))

React.useEffect1(() => {
[
(optionsPayment.defaultValues.billingDetails.name, setUserFullName),
(optionsPayment.defaultValues.billingDetails.email, setUserEmail),
(optionsPayment.defaultValues.billingDetails.address.line1, setUserAddressline1),
(optionsPayment.defaultValues.billingDetails.address.line2, setUserAddressline2),
(optionsPayment.defaultValues.billingDetails.address.city, setUserAddressCity),
(optionsPayment.defaultValues.billingDetails.address.postal_code, setUserAddressPincode),
(optionsPayment.defaultValues.billingDetails.address.state, setUserAddressState),
(optionsPayment.defaultValues.billingDetails.address.country, setUserAddressCountry),
]->Js.Array2.forEach(val => {
let (value, setValue) = val
if value != "" {
setValue(.
prev => {
...prev,
value,
},
)
}
})
if optionsPayment.defaultValues.billingDetails.address.country === "" {
let clientTimeZone = CardUtils.dateTimeFormat(.).resolvedOptions(.).timeZone
let clientCountry = Utils.getClientCountry(clientTimeZone)
setUserAddressCountry(.prev => {
...prev,
value: clientCountry.countryName,
})
setCountry(._ => clientCountry.countryName)
} else {
setUserAddressCountry(.prev => {
...prev,
value: optionsPayment.defaultValues.billingDetails.address.country,
})
setCountry(._ => optionsPayment.defaultValues.billingDetails.address.country)
}
None
}, [optionsPayment])

React.useEffect1(() => {
switch paymentlist {
| Loaded(_)
Expand Down

0 comments on commit 729bf3c

Please sign in to comment.