From d2b75a4083da0a6f7b7e33dbd42c9dc87ec1ea1b Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja <1805317@kiit.ac.in> Date: Mon, 15 Apr 2024 17:12:48 +0530 Subject: [PATCH] fix: paypal issue for Ideal Fix --- src/Components/DropdownField.res | 2 +- src/Payments/PaymentMethodsRecord.res | 29 +++++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) 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 } }