Skip to content

Commit

Permalink
refactor: moved dynamic fields payment method array inside dynamic fi…
Browse files Browse the repository at this point in the history
…eld utils
  • Loading branch information
sakksham7 committed Nov 7, 2024
1 parent f86f7dc commit 3755c5c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
27 changes: 12 additions & 15 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
open RecoilAtoms
@react.component
let make = (
~paymentType,
Expand All @@ -12,7 +11,9 @@ let make = (
~cvcProps=None,
~isBancontact=false,
) => {
open DynamicFieldsUtils
open Utils
open RecoilAtoms
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)

React.useEffect(() => {
Expand Down Expand Up @@ -41,20 +42,16 @@ let make = (

paymentMethodTypes.required_fields
->Array.concat(creditRequiredFields)
->DynamicFieldsUtils.removeRequiredFieldsDuplicates
} else if (
PaymentMethodsRecord.dynamicFieldsEnabledPaymentMethods->Array.includes(paymentMethodType)
) {
->removeRequiredFieldsDuplicates
} else if dynamicFieldsEnabledPaymentMethods->Array.includes(paymentMethodType) {
paymentMethodTypes.required_fields
} else {
[]
}
}, (paymentMethod, paymentMethodTypes.required_fields, paymentMethodType))

let requiredFields = React.useMemo(() => {
requiredFieldsWithBillingDetails->DynamicFieldsUtils.removeBillingDetailsIfUseBillingAddress(
billingAddress,
)
requiredFieldsWithBillingDetails->removeBillingDetailsIfUseBillingAddress(billingAddress)
}, [requiredFieldsWithBillingDetails])

let isAllStoredCardsHaveName = React.useMemo(() => {
Expand All @@ -69,7 +66,7 @@ let make = (
~isSavedCardFlow,
~isAllStoredCardsHaveName,
)
->DynamicFieldsUtils.updateDynamicFields(billingAddress)
->updateDynamicFields(billingAddress)
->Belt.SortArray.stableSortBy(PaymentMethodsRecord.sortPaymentMethodFields)
//<...>//
}, (requiredFields, isAllStoredCardsHaveName, isSavedCardFlow))
Expand Down Expand Up @@ -255,7 +252,7 @@ let make = (
}
}

DynamicFieldsUtils.useRequiredFieldsEmptyAndValid(
useRequiredFieldsEmptyAndValid(
~requiredFields,
~fieldsArr,
~countryNames,
Expand All @@ -268,14 +265,14 @@ let make = (
~cvcNumber,
)

DynamicFieldsUtils.useSetInitialRequiredFields(
useSetInitialRequiredFields(
~requiredFields={
billingAddress.usePrefilledValues === Auto ? requiredFieldsWithBillingDetails : requiredFields
},
~paymentMethodType,
)

DynamicFieldsUtils.useRequiredFieldsBody(
useRequiredFieldsBody(
~requiredFields,
~paymentMethodType,
~cardNumber,
Expand All @@ -286,7 +283,7 @@ let make = (
~setRequiredFieldsBody,
)

let submitCallback = DynamicFieldsUtils.useSubmitCallback()
let submitCallback = useSubmitCallback()
useSubmitPaymentData(submitCallback)

let bottomElement = <InfoElement />
Expand All @@ -307,11 +304,11 @@ let make = (
}

let dynamicFieldsToRenderOutsideBilling = React.useMemo(() => {
fieldsArr->Array.filter(DynamicFieldsUtils.isFieldTypeToRenderOutsideBilling)
fieldsArr->Array.filter(isFieldTypeToRenderOutsideBilling)
}, [fieldsArr])

let dynamicFieldsToRenderInsideBilling = React.useMemo(() => {
fieldsArr->Array.filter(field => !(field->DynamicFieldsUtils.isFieldTypeToRenderOutsideBilling))
fieldsArr->Array.filter(field => !(field->isFieldTypeToRenderOutsideBilling))
}, [fieldsArr])

let isInfoElementPresent = dynamicFieldsToRenderInsideBilling->Array.includes(InfoElement)
Expand Down
23 changes: 0 additions & 23 deletions src/Payments/PaymentMethodsRecord.res
Original file line number Diff line number Diff line change
Expand Up @@ -661,29 +661,6 @@ let getFieldType = (dict, isBancontact) => {
}
}

let dynamicFieldsEnabledPaymentMethods = [
"crypto_currency",
"debit",
"credit",
"blik",
"google_pay",
"apple_pay",
"bancontact_card",
"open_banking_uk",
"eps",
"ideal",
"sofort",
"pix_transfer",
"giropay",
"local_bank_transfer_transfer",
"afterpay_clearpay",
"mifinity",
"upi_collect",
"sepa",
"affirm",
"ach",
]

let getIsBillingField = requiredFieldType => {
switch requiredFieldType {
| AddressLine1
Expand Down
23 changes: 23 additions & 0 deletions src/Utilities/DynamicFieldsUtils.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
open RecoilAtoms

let dynamicFieldsEnabledPaymentMethods = [
"crypto_currency",
"debit",
"credit",
"blik",
"google_pay",
"apple_pay",
"bancontact_card",
"open_banking_uk",
"eps",
"ideal",
"sofort",
"pix_transfer",
"giropay",
"local_bank_transfer_transfer",
"afterpay_clearpay",
"mifinity",
"upi_collect",
"sepa",
"affirm",
"ach",
]

let getName = (item: PaymentMethodsRecord.required_fields, field: RecoilAtomTypes.field) => {
let fieldNameArr = field.value->String.split(" ")
let requiredFieldsArr = item.required_field->String.split(".")
Expand Down

0 comments on commit 3755c5c

Please sign in to comment.