Skip to content

Commit

Permalink
fix: country code multiple same code fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja committed Apr 26, 2024
1 parent 32563dd commit bc992df
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Components/PhoneNumberPaymentInput.res
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let make = () => {
let phoneNumberOptionsValue: DropdownField.optionType = {
label: `${countryFlag} ${countryName} ${phoneNumberCode}`,
displayValue: `${countryFlag} ${phoneNumberCode}`,
value: phoneNumberCode,
value: `${countryFlag}#${phoneNumberCode}`,
}
acc->Array.push(phoneNumberOptionsValue)
acc
Expand All @@ -51,20 +51,21 @@ let make = () => {
->getString("phone_number_code", "")

let (valueDropDown, setValueDropDown) = React.useState(_ => defaultCountryCodeFilteredValue)
let getCountryCodeSplitValue = val => val->String.split("#")->Array.get(1)->Option.getOr("")

let changePhone = ev => {
let val: string = ReactEvent.Form.target(ev)["value"]->String.replaceRegExp(%re("/\+D+/g"), "")
setPhone(prev => {
...prev,
countryCode: valueDropDown,
countryCode: valueDropDown->getCountryCodeSplitValue,
value: val,
})
}

React.useEffect(() => {
setPhone(prev => {
...prev,
countryCode: valueDropDown,
countryCode: valueDropDown->getCountryCodeSplitValue,
})
None
}, [valueDropDown])
Expand Down

0 comments on commit bc992df

Please sign in to comment.