Skip to content

Commit

Permalink
fix: HS-1111: fixed addres state (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
prafulkoppalkar authored Feb 12, 2024
1 parent 4f87fd2 commit a91cfd9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let make = (
~isAllStoredCardsHaveName,
(),
)
->DynamicFieldsUtils.updateDynamicFields()
->DynamicFieldsUtils.updateDynamicFields(billingAddress, ())
->Belt.SortArray.stableSortBy(PaymentMethodsRecord.sortPaymentMethodFields)
//<...>//
}, (requiredFields, isAllStoredCardsHaveName, isSavedCardFlow))
Expand Down
18 changes: 12 additions & 6 deletions src/Utilities/DynamicFieldsUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -614,11 +616,15 @@ let combineCardExpiryAndCvc = arr => {
}
}

let updateDynamicFields = (arr: Js.Array2.t<PaymentMethodsRecord.paymentMethodsFields>, ()) => {
let updateDynamicFields = (
arr: Js.Array2.t<PaymentMethodsRecord.paymentMethodsFields>,
billingAddress,
(),
) => {
arr
->Utils.removeDuplicate
->Js.Array2.filter(item => item !== None)
->addBillingAddressIfUseBillingAddress
->addBillingAddressIfUseBillingAddress(billingAddress)
->combineStateAndCity
->combineCountryAndPostal
->combineCardExpiryMonthAndYear
Expand Down

0 comments on commit a91cfd9

Please sign in to comment.