diff --git a/src/Components/DropdownField.res b/src/Components/DropdownField.res index 45c496e76..09a54d5a6 100644 --- a/src/Components/DropdownField.res +++ b/src/Components/DropdownField.res @@ -29,7 +29,7 @@ let make = ( themeObj.colorBackground }, [themeObj]) React.useEffect0(() => { - if value === "" { + if value === "" || !(options->Array.includes(value)) { setValue(_ => options->Array.get(0)->Option.getOr("")) } None diff --git a/src/Payments/PaymentMethodsRecord.res b/src/Payments/PaymentMethodsRecord.res index 6fff42908..d00db5951 100644 --- a/src/Payments/PaymentMethodsRecord.res +++ b/src/Payments/PaymentMethodsRecord.res @@ -523,6 +523,20 @@ let getPaymentMethodsFieldTypeFromString = (str, isBancontact) => { } } +let getOptionsFromPaymentMethodFieldType = (dict, key) => { + let options = dict->Utils.getArrayValFromJsonDict(key, "options") + switch options->Array.get(0)->Option.getOr("") { + | "" => None + | "ALL" => AddressCountry(Country.country->Array.map(item => item.countryName)) + | _ => + AddressCountry( + Country.country + ->Array.filter(item => options->Array.includes(item.isoAlpha2)) + ->Array.map(item => item.countryName), + ) + } +} + let getPaymentMethodsFieldTypeFromDict = dict => { let keysArr = dict->Dict.keysToArray let key = keysArr->Array.get(0)->Option.getOr("") @@ -531,19 +545,8 @@ let getPaymentMethodsFieldTypeFromDict = dict => { let options = dict->Utils.getArrayValFromJsonDict("user_currency", "options") Currency(options) } - | "user_address_country" => { - let options = dict->Utils.getArrayValFromJsonDict("user_address_country", "options") - switch options->Array.get(0)->Option.getOr("") { - | "" => None - | "ALL" => AddressCountry(Country.country->Array.map(item => item.countryName)) - | _ => - AddressCountry( - Country.country - ->Array.filter(item => options->Array.includes(item.isoAlpha2)) - ->Array.map(item => item.countryName), - ) - } - } + | "user_country" => dict->getOptionsFromPaymentMethodFieldType("user_country") + | "user_address_country" => dict->getOptionsFromPaymentMethodFieldType("user_address_country") | _ => None } }