From 729bf3c813a9b80dcd31afce37a13e9e573ec2a5 Mon Sep 17 00:00:00 2001 From: Arun Mishra <68141066+arun-mi@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:59:29 +0530 Subject: [PATCH] fix:HS:132: Country if prefilled will be taken as such and not from client timezone (#77) Co-authored-by: arun.mishra --- src/Components/DynamicFields.res | 9 ++-- src/LoaderController.res | 81 ++++++++++++++++---------------- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/src/Components/DynamicFields.res b/src/Components/DynamicFields.res index 9e0515634..124d609e5 100644 --- a/src/Components/DynamicFields.res +++ b/src/Components/DynamicFields.res @@ -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 @@ -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 === "" { diff --git a/src/LoaderController.res b/src/LoaderController.res index 2a042ea28..92e7e0c76 100644 --- a/src/LoaderController.res +++ b/src/LoaderController.res @@ -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 { @@ -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) + } | _ => () } } @@ -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(_)