Skip to content

Commit

Permalink
fix: comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja committed Apr 18, 2024
1 parent c638e66 commit df49579
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 74 deletions.
12 changes: 7 additions & 5 deletions src/Components/DropdownField.res
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
type optionType = {
label: string,
value: string,
label?: string,
displayValue?: string,
}

let updateArrayOfStringToOptionsTypeArray = arrayOfString =>
arrayOfString->Array.map(item => {
value: item,
})

open RecoilAtoms
@react.component
let make = (
Expand Down Expand Up @@ -39,9 +44,7 @@ let make = (
options
->Array.find((ele: optionType) => ele.value === value)
->Option.getOr({
label: "",
value: "",
displayValue: "",
})

switch setDisplayValue {
Expand All @@ -60,7 +63,6 @@ let make = (
options
->Array.get(0)
->Option.getOr({
label: "",
value: "",
})
).value
Expand Down Expand Up @@ -120,7 +122,7 @@ let make = (
{options
->Array.mapWithIndex((item, index) => {
<option key={Int.toString(index)} value=item.value>
{React.string(item.label)}
{React.string(item.label->Option.getOr(item.value))}
</option>
})
->React.array}
Expand Down
55 changes: 10 additions & 45 deletions src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,8 @@ let make = (
/>
</div>
| Currency(currencyArr) =>
let updatedCurrencyArray: array<
DropdownField.optionType,
> = currencyArr->Array.map(item => {
let optionVal: DropdownField.optionType = {
label: item,
value: item,
}
optionVal
})
let updatedCurrencyArray =
currencyArr->DropdownField.updateArrayOfStringToOptionsTypeArray
<DropdownField
appearance=config.appearance
fieldName=localeString.currencyLabel
Expand Down Expand Up @@ -533,15 +526,8 @@ let make = (
}}
</div>
| CountryAndPincode(countryArr) =>
let updatedCountryArray: array<
DropdownField.optionType,
> = countryArr->Array.map(item => {
let optionVal: DropdownField.optionType = {
label: item,
value: item,
}
optionVal
})
let updatedCountryArray =
countryArr->DropdownField.updateArrayOfStringToOptionsTypeArray
<div className="flex gap-1">
<DropdownField
appearance=config.appearance
Expand Down Expand Up @@ -682,15 +668,8 @@ let make = (
/>
| BlikCode => <BlikCodePaymentInput />
| Country =>
let updatedCountryNames: array<
DropdownField.optionType,
> = countryNames->Array.map(item => {
let optionVal: DropdownField.optionType = {
label: item,
value: item,
}
optionVal
})
let updatedCountryNames =
countryNames->DropdownField.updateArrayOfStringToOptionsTypeArray
<DropdownField
appearance=config.appearance
fieldName=localeString.countryLabel
Expand All @@ -700,15 +679,8 @@ let make = (
options=updatedCountryNames
/>
| AddressCountry(countryArr) =>
let updatedCountryArr: array<
DropdownField.optionType,
> = countryArr->Array.map(item => {
let optionVal: DropdownField.optionType = {
label: item,
value: item,
}
optionVal
})
let updatedCountryArr =
countryArr->DropdownField.updateArrayOfStringToOptionsTypeArray
<DropdownField
appearance=config.appearance
fieldName=localeString.countryLabel
Expand All @@ -718,15 +690,8 @@ let make = (
options=updatedCountryArr
/>
| Bank =>
let updatedBankNames: array<
DropdownField.optionType,
> = bankNames->Array.map(item => {
let optionVal: DropdownField.optionType = {
label: item,
value: item,
}
optionVal
})
let updatedBankNames =
bankNames->DropdownField.updateArrayOfStringToOptionsTypeArray
<DropdownField
appearance=config.appearance
fieldName=localeString.bankLabel
Expand Down
24 changes: 12 additions & 12 deletions src/Components/PhoneNumberPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ let make = () => {
DropdownField.optionType,
> = countryAndCodeCodeList->Array.reduce([], (acc, countryObj) => {
let countryObjDict = countryObj->getDictFromJson
let countryFlag = countryObjDict->getString("country_flag", "")
let phoneNumberCode = countryObjDict->getString("phone_number_code", "")
let countryName = countryObjDict->getString("country_name", "")

let phoneNumberOptionsValue: DropdownField.optionType = {
label: `${countryObjDict->getString("country_flag", "")} ${countryObjDict->getString(
"country_name",
"",
)} ${countryObjDict->getString("phone_number_code", "")}`,
displayValue: `${countryObjDict->getString("country_flag", "")} ${countryObjDict->getString(
"phone_number_code",
"",
)}`,
value: countryObjDict->getString("phone_number_code", ""),
label: `${countryFlag} ${countryName} ${phoneNumberCode}`,
displayValue: `${countryFlag} ${phoneNumberCode}`,
value: phoneNumberCode,
}
acc->Array.push(phoneNumberOptionsValue)
acc
Expand Down Expand Up @@ -76,11 +74,13 @@ let make = () => {
phoneNumberCodeOptions
->Array.find(ele => ele.value === valueDropDown)
->Option.getOr({
label: "",
value: "",
displayValue: "",
})
setDisplayValue(_ => findDisplayValue.displayValue->Option.getOr(findDisplayValue.label))
setDisplayValue(_ =>
findDisplayValue.displayValue->Option.getOr(
findDisplayValue.label->Option.getOr(findDisplayValue.value),
)
)
None
}, [phoneNumberCodeOptions])

Expand Down
2 changes: 0 additions & 2 deletions src/Payments/BankDebitModal.res
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,9 @@ let make = (~setModalData) => {
disabled=false
options=[
{
label: "Savings",
value: "Savings",
},
{
label: "Checking",
value: "Checking",
},
]
Expand Down
3 changes: 2 additions & 1 deletion src/Payments/KlarnaPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ let make = (~paymentType, ~list: PaymentMethodsRecord.list) => {
let (fullName, _) = Recoil.useLoggedRecoilState(userFullName, "fullName", loggerState)
let (email, _) = Recoil.useLoggedRecoilState(userEmailAddress, "email", loggerState)

let countryNames = Utils.getCountryNames(Country.country)
let countryNames =
Utils.getCountryNames(Country.country)->DropdownField.updateArrayOfStringToOptionsTypeArray

let (country, setCountry) = Recoil.useRecoilState(userCountry)
let setCountry = val => {
Expand Down
11 changes: 2 additions & 9 deletions src/Payments/SepaBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,8 @@ let make = (~paymentType, ~list) => {
}, (email, fullName, country))
useSubmitPaymentData(submitCallback)

let updatedOptionsArrayForCountry: array<
DropdownField.optionType,
> = countryNames->Array.map(item => {
let optionVal: DropdownField.optionType = {
label: item,
value: item,
}
optionVal
})
let updatedOptionsArrayForCountry =
countryNames->DropdownField.updateArrayOfStringToOptionsTypeArray

<div
className="flex flex-col animate-slowShow"
Expand Down

0 comments on commit df49579

Please sign in to comment.