Skip to content

Commit

Permalink
Update logic to store and update phone number code
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-claudio committed Jul 5, 2024
1 parent 73b9fb8 commit ba02bb2
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,21 @@ export const PhoneNumberInput = forwardRef<
) {
return;
}

const selectedCountry = countryCodeRef?.current?.value;
if (!selectedCountry) {
return;
}
const code = countryCode.options
// Match longer, more specific country codes first
.sort((a, b) => a.code.length - b.code.length)
.find(({ country }) => country === selectedCountry)?.code;

if (!code) {
return;
}
const phoneNumber = normalizePhoneNumber(
countryCode.options.find(
({ country }) => country === countryCodeRef?.current?.value,
)?.code as string,
code,
subscriberNumberRef.current.value,
);
onChange(phoneNumber);
Expand Down

0 comments on commit ba02bb2

Please sign in to comment.