From a91cfd9ab2331760032221d732e92b02a4b40750 Mon Sep 17 00:00:00 2001 From: Praful Koppalkar <126236898+prafulkoppalkar@users.noreply.github.com> Date: Mon, 12 Feb 2024 14:54:53 +0530 Subject: [PATCH] fix: HS-1111: fixed addres state (#151) --- src/Components/DynamicFields.res | 2 +- src/Utilities/DynamicFieldsUtils.res | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Components/DynamicFields.res b/src/Components/DynamicFields.res index da01d1899..979168ace 100644 --- a/src/Components/DynamicFields.res +++ b/src/Components/DynamicFields.res @@ -57,7 +57,7 @@ let make = ( ~isAllStoredCardsHaveName, (), ) - ->DynamicFieldsUtils.updateDynamicFields() + ->DynamicFieldsUtils.updateDynamicFields(billingAddress, ()) ->Belt.SortArray.stableSortBy(PaymentMethodsRecord.sortPaymentMethodFields) //<...>// }, (requiredFields, isAllStoredCardsHaveName, isSavedCardFlow)) diff --git a/src/Utilities/DynamicFieldsUtils.res b/src/Utilities/DynamicFieldsUtils.res index caaf98e19..6ef642d75 100644 --- a/src/Utilities/DynamicFieldsUtils.res +++ b/src/Utilities/DynamicFieldsUtils.res @@ -61,9 +61,10 @@ let removeBillingDetailsIfUseBillingAddress = ( } } -let addBillingAddressIfUseBillingAddress = fieldsArr => { - let {billingAddress} = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom) - +let addBillingAddressIfUseBillingAddress = ( + fieldsArr, + billingAddress: PaymentType.billingAddress, +) => { if billingAddress.isUseBillingAddress { fieldsArr->Js.Array2.concat(billingAddressFields) } else { @@ -119,8 +120,9 @@ let useRequiredFieldsEmptyAndValid = ( let currency = Recoil.useRecoilValueFromAtom(RecoilAtoms.userCurrency) let setAreRequiredFieldsValid = Recoil.useSetRecoilState(RecoilAtoms.areRequiredFieldsValid) let setAreRequiredFieldsEmpty = Recoil.useSetRecoilState(RecoilAtoms.areRequiredFieldsEmpty) + let {billingAddress} = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom) - let fieldsArrWithBillingAddress = fieldsArr->addBillingAddressIfUseBillingAddress + let fieldsArrWithBillingAddress = fieldsArr->addBillingAddressIfUseBillingAddress(billingAddress) React.useEffect7(() => { let areRequiredFieldsValid = fieldsArr->Js.Array2.reduce((acc, paymentMethodFields) => { @@ -614,11 +616,15 @@ let combineCardExpiryAndCvc = arr => { } } -let updateDynamicFields = (arr: Js.Array2.t, ()) => { +let updateDynamicFields = ( + arr: Js.Array2.t, + billingAddress, + (), +) => { arr ->Utils.removeDuplicate ->Js.Array2.filter(item => item !== None) - ->addBillingAddressIfUseBillingAddress + ->addBillingAddressIfUseBillingAddress(billingAddress) ->combineStateAndCity ->combineCountryAndPostal ->combineCardExpiryMonthAndYear