Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(payout): on change handler for dropdown #615

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/CollectWidget.res
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,12 @@ let make = (
fieldName={field->getPaymentMethodDataFieldLabel(localeString)}
value
setValue={getVal => {
let isValid = calculateValidity(field, getVal(), ~default=Some(false))
let updatedValue = getVal()
let isValid = calculateValidity(field, updatedValue, ~default=Some(false))
setValidityDictVal(key, isValid)
if isValid->Option.getOr(false) {
setFormData(key, updatedValue)
}
}}
options={countries->DropdownField.updateArrayOfStringToOptionsTypeArray}
disabled=false
Expand Down
6 changes: 4 additions & 2 deletions src/FormViewTabs.res
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ let make = (
{payoutDynamicFields.payoutMethodData->renderPayoutMethodForm->React.array}
{payoutDynamicFields.address
->Option.map(addressFields => {
let formFields = addressFields->renderAddressForm
if formFields->Array.length > 0 {
let fieldsToCollect =
addressFields->Array.filter(addressField => addressField.value == None)
if fieldsToCollect->Array.length > 0 {
let formFields = addressFields->renderAddressForm
<>
<div className={`mb-2.5 ${contentHeaderClasses}`}>
{React.string(localeString.billingDetailsText)}
Expand Down
2 changes: 1 addition & 1 deletion src/PaymentMethodCollectElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ let make = (~integrateError, ~logger) => {

let renderCollectWidget = () =>
<div className="flex flex-row overflow-scroll lg:w-6/10">
<div className="relative w-full h-auto lg:w-auto lg:mx-12 lg:mt-20 lg-mb-10">
<div className="relative w-full h-min lg:w-auto lg:mx-12 lg:mt-20 lg-mb-10">
{loader
? <div className="absolute h-full w-full bg-jp-gray-600 bg-opacity-80" />
: {React.null}}
Expand Down
29 changes: 22 additions & 7 deletions src/Types/PaymentMethodCollectTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,15 @@ let getFieldOptions = dict => {
obj
->Dict.get("options")
->Option.flatMap(JSON.Decode.array)
->Option.map(options => BillingAddress(
AddressCountry(options->Array.filterMap(option => option->JSON.Decode.string)),
))
->Option.map(options => {
let countries = options->Array.filterMap(option => option->JSON.Decode.string)
countries->Array.sort(
(c1, c2) =>
(c1->String.charCodeAt(0)->Float.toInt - c2->String.charCodeAt(0)->Float.toInt)
->Int.toFloat,
)
BillingAddress(AddressCountry(countries))
})
)
| _ => None
}
Expand Down Expand Up @@ -338,7 +344,9 @@ let sortByCustomOrder = (arr: array<'a>, getKey: 'a => string, customOrder: arra
})
}

let decodePayoutDynamicFields = (json: JSON.t): option<payoutDynamicFields> =>
let decodePayoutDynamicFields = (json: JSON.t, defaultDynamicPmdFields): option<
payoutDynamicFields,
> =>
json
->JSON.Decode.object
->Option.map(obj => {
Expand Down Expand Up @@ -382,7 +390,9 @@ let decodePayoutDynamicFields = (json: JSON.t): option<payoutDynamicFields> =>
address: address->Array.length > 0
? Some(sortByCustomOrder(address, item => item.pmdMap, customAddressOrder))
: None,
payoutMethodData: sortByCustomOrder(pmd, item => item.pmdMap, customPmdOrder),
payoutMethodData: pmd->Array.length > 0
? sortByCustomOrder(pmd, item => item.pmdMap, customPmdOrder)
: defaultDynamicPmdFields,
}
})

Expand Down Expand Up @@ -427,15 +437,20 @@ let decodePaymentMethodTypeWithRequiredFields = (
let payoutDynamicFields =
obj
->Dict.get("required_fields")
->Option.flatMap(decodePayoutDynamicFields)
->Option.flatMap(
json => json->decodePayoutDynamicFields(defaultDynamicPmdFields(~pmt)),
)
->Option.getOr({
address: None,
payoutMethodData: defaultDynamicPmdFields(~pmt),
})
switch pmt {
| Card(card) => {
pmta->Array.push(Card(card))
let pmtwr: paymentMethodTypeWithDynamicFields = Card(card, payoutDynamicFields)
let pmtwr: paymentMethodTypeWithDynamicFields = Card(
card,
payoutDynamicFields,
)
pmtr->Array.push(pmtwr)
(pmta, pmtr)
}
Expand Down
21 changes: 13 additions & 8 deletions src/Utilities/PaymentMethodCollectUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ let getPaymentMethodDataFieldCharacterPattern = (key): option<Js.Re.t> =>
| PayoutMethodData(PaypalMobNumber) => Some(%re("/^[0-9]{1,12}$/"))
| PayoutMethodData(SepaBic) => Some(%re("/^([A-Z0-9]| ){1,8}$/"))
| PayoutMethodData(SepaIban) => Some(%re("/^([A-Z0-9]| ){1,34}$/"))
| BillingAddress(AddressPincode) => Some(%re("/^[0-9]{1,8}$/"))
| BillingAddress(AddressPincode) => Some(%re("/^([0-9A-Z]| ){1,10}$/"))
| BillingAddress(PhoneNumber) => Some(%re("/^[0-9]{1,12}$/"))
| BillingAddress(PhoneCountryCode) => Some(%re("/^[0-9]{1,2}$/"))
| _ => None
Expand Down Expand Up @@ -521,7 +521,7 @@ let defaultPaypalFields = [
{
pmdMap: "payout_method_data.wallet.telephone_number",
displayName: "user_phone_number",
fieldType: SepaIban,
fieldType: PaypalMobNumber,
value: None,
},
]
Expand Down Expand Up @@ -565,12 +565,12 @@ let defaultEnabledPaymentMethods: array<paymentMethodType> = [
Wallet(Paypal),
]
let defaultEnabledPaymentMethodsWithDynamicFields: array<paymentMethodTypeWithDynamicFields> = [
Card((Credit, defaultPayoutDynamicFields())),
Card((Debit, defaultPayoutDynamicFields())),
BankTransfer((ACH, defaultPayoutDynamicFields())),
BankTransfer((Bacs, defaultPayoutDynamicFields())),
BankTransfer((Sepa, defaultPayoutDynamicFields())),
Wallet((Paypal, defaultPayoutDynamicFields())),
Card((Credit, defaultPayoutDynamicFields(~pmt=Card(Credit)))),
Card((Debit, defaultPayoutDynamicFields(~pmt=Card(Debit)))),
BankTransfer((ACH, defaultPayoutDynamicFields(~pmt=BankTransfer(ACH)))),
BankTransfer((Bacs, defaultPayoutDynamicFields(~pmt=BankTransfer(Bacs)))),
BankTransfer((Sepa, defaultPayoutDynamicFields(~pmt=BankTransfer(Sepa)))),
Wallet((Paypal, defaultPayoutDynamicFields(~pmt=Wallet(Paypal)))),
]
let defaultPaymentMethodCollectOptions = {
enabledPaymentMethods: defaultEnabledPaymentMethods,
Expand Down Expand Up @@ -696,6 +696,11 @@ let calculateValidity = (key, value, ~default=None) => {
} else {
Some(false)
}
| PayoutMethodData(SepaIban) => Some(value->String.length > 13 && value->String.length < 34)

// Sepa BIC is optional
| PayoutMethodData(SepaBic) => Some(true)

// Defaults
| PayoutMethodData(_)
| BillingAddress(_) =>
Expand Down
Loading