Skip to content

Commit

Permalink
feat: phone country code accept (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
rising-dragon401 committed Jun 20, 2024
1 parent 773c632 commit 8a39d1b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ let make = (
| ShippingAddressCity
| ShippingAddressPincode
| ShippingAddressState
| PhoneCountryCode
| ShippingAddressCountry(_) => React.null
}}
</div>
Expand Down Expand Up @@ -763,6 +764,7 @@ let make = (
| ShippingAddressCountry(_)
| CryptoCurrencyNetworks
| DateOfBirth
| PhoneCountryCode
| None => React.null
}}
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/Payments/PaymentMethodsRecord.res
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type paymentMethodsFields =
| None
| BillingName
| PhoneNumber
| PhoneCountryCode
| AddressLine1
| AddressLine2
| AddressCity
Expand Down Expand Up @@ -558,6 +559,7 @@ let getPaymentMethodsFieldTypeFromString = (str, isBancontact) => {
| ("user_shipping_address_state", _) => ShippingAddressState
| ("user_crypto_currency_network", _) => CryptoCurrencyNetworks
| ("user_date_of_birth", _) => DateOfBirth
| ("user_phone_number_country_code", _) => PhoneCountryCode
| _ => None
}
}
Expand Down
35 changes: 27 additions & 8 deletions src/Utilities/DynamicFieldsUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,32 @@ let useSetInitialRequiredFields = (
field: RecoilAtomTypes.field,
item: PaymentMethodsRecord.required_fields,
isNameField,
~isCountryCodeAvailable=?,
) => {
if isNameField && field.value === "" {
setMethod(prev => {
...prev,
value: getNameValue(item),
})
if isCountryCodeAvailable->Option.isSome {
setMethod(prev => {
...prev,
countryCode: getNameValue(item),
})
} else {
setMethod(prev => {
...prev,
value: getNameValue(item),
})
}
} else if field.value === "" {
setMethod(prev => {
...prev,
value: item.value,
})
if isCountryCodeAvailable->Option.isSome {
setMethod(prev => {
...prev,
countryCode: item.value,
})
} else {
setMethod(prev => {
...prev,
value: item.value,
})
}
}
}

Expand Down Expand Up @@ -338,6 +353,8 @@ let useSetInitialRequiredFields = (
}
| AddressState => setFields(setState, state, requiredField, false)
| AddressCity => setFields(setCity, city, requiredField, false)
| PhoneCountryCode =>
setFields(setPhone, phone, requiredField, false, ~isCountryCodeAvailable=true)
| AddressPincode => setFields(setPostalCode, postalCode, requiredField, false)
| PhoneNumber => setFields(setPhone, phone, requiredField, false)
| BlikCode => setFields(setBlikCode, blikCode, requiredField, false)
Expand Down Expand Up @@ -427,6 +444,7 @@ let useRequiredFieldsBody = (
| AddressState => state.value
| BlikCode => blikCode.value->Utils.removeHyphen
| PhoneNumber => phone.value
| PhoneCountryCode => phone.countryCode->Option.getOr("")
| Currency(_) => currency
| Country => country
| Bank =>
Expand Down Expand Up @@ -538,6 +556,7 @@ let useRequiredFieldsBody = (
state.value,
blikCode.value,
phone.value,
phone.countryCode,
currency,
billingName.value,
country,
Expand Down

0 comments on commit 8a39d1b

Please sign in to comment.