From 426415a8c88e56bd0e6b84da56982c1e40082c67 Mon Sep 17 00:00:00 2001 From: Praful Koppalkar <126236898+prafulkoppalkar@users.noreply.github.com> Date: Fri, 16 Feb 2024 02:15:44 +0530 Subject: [PATCH] fix: HS-111: Added billing name to address element (#145) --- src/Components/DynamicFields.res | 18 ++++++++---------- src/Utilities/DynamicFieldsUtils.res | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Components/DynamicFields.res b/src/Components/DynamicFields.res index 14cb711c4..76e2a3737 100644 --- a/src/Components/DynamicFields.res +++ b/src/Components/DynamicFields.res @@ -486,8 +486,13 @@ let make = ( disabled=false options=currencyArr /> + | FullName => + getCustomFieldName} + optionalRequiredFields={Some(requiredFields)} + /> | Email - | FullName | InfoElement | Country | Bank @@ -525,17 +530,9 @@ let make = ( key={`inside-billing-${index->Js.Int.toString}`} className="flex flex-col w-full place-content-between"> {switch item { - | FullName => - getCustomFieldName} - optionalRequiredFields={Some(requiredFields)} - /> | BillingName => getCustomFieldName} - optionalRequiredFields={Some(requiredFields)} + paymentType optionalRequiredFields={Some(requiredFields)} /> | Email => | PhoneNumber => @@ -728,6 +725,7 @@ let make = ( | CardCvc | CardExpiryAndCvc | Currency(_) + | FullName | None => React.null }} diff --git a/src/Utilities/DynamicFieldsUtils.res b/src/Utilities/DynamicFieldsUtils.res index 603c77f57..5b55cc900 100644 --- a/src/Utilities/DynamicFieldsUtils.res +++ b/src/Utilities/DynamicFieldsUtils.res @@ -15,6 +15,7 @@ let getName = (item: PaymentMethodsRecord.required_fields, field: RecoilAtomType let countryNames = Utils.getCountryNames(Country.country) let billingAddressFields: array = [ + BillingName, AddressLine1, AddressLine2, AddressCity, @@ -25,6 +26,7 @@ let billingAddressFields: array = [ let isBillingAddressFieldType = (fieldType: PaymentMethodsRecord.paymentMethodsFields) => { switch fieldType { + | BillingName | AddressLine1 | AddressLine2 | AddressCity @@ -429,6 +431,7 @@ let useRequiredFieldsBody = ( ->Belt.Option.getWithDefault(Country.defaultTimeZone) countryCode.isoAlpha2 } + | BillingName => billingName.value | CardNumber => cardNumber->CardUtils.clearSpaces | CardExpiryMonth => let (month, _) = CardUtils.getExpiryDates(cardExpiry) @@ -444,7 +447,6 @@ let useRequiredFieldsBody = ( | CardExpiryMonthAndYear | CardExpiryAndCvc | FullName - | BillingName | None => "" } } @@ -453,8 +455,20 @@ let useRequiredFieldsBody = ( if billingAddress.isUseBillingAddress { billingAddressFields->Js.Array2.reduce((acc, item) => { let value = item->getFieldValueFromFieldType - let path = item->getBillingAddressPathFromFieldType - acc->Js.Dict.set(path, value->Js.Json.string) + if item === BillingName { + let arr = value->Js.String2.split(" ") + acc->Js.Dict.set( + "billing.address.first_name", + arr->Belt.Array.get(0)->Belt.Option.getWithDefault("")->Js.Json.string, + ) + acc->Js.Dict.set( + "billing.address.last_name", + arr->Belt.Array.get(1)->Belt.Option.getWithDefault("")->Js.Json.string, + ) + } else { + let path = item->getBillingAddressPathFromFieldType + acc->Js.Dict.set(path, value->Js.Json.string) + } acc }, requiredFieldsBody) } else { @@ -514,6 +528,7 @@ let useRequiredFieldsBody = ( let isFieldTypeToRenderOutsideBilling = (fieldType: PaymentMethodsRecord.paymentMethodsFields) => { switch fieldType { + | FullName | CardNumber | CardExpiryMonth | CardExpiryYear