Skip to content

Commit

Permalink
Fix issue with formatting national phone numbers for countries with a…
Browse files Browse the repository at this point in the history
… '0' national prefix
  • Loading branch information
tareq89 committed Jan 10, 2025
1 parent 6a0f9e0 commit fd4b0dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
- Fix the informant column on the Perfomance page showing "Other family member" when `Someone else` is selected for a registration [#6157](https://github.com/opencrvs/opencrvs-core/issues/6157)
- Fix the event name displayed in email templates for death correction requests [#7703](https://github.com/opencrvs/opencrvs-core/issues/7703)

## 1.6.3 Release candidate

### Improvements

- Refactored convertToLocal to handle optional country code, fallback region detection, and special handling for national prefixes (e.g., 0), with alphanumeric sanitization of phone numbers.

## 1.6.2 Release candidate

### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export const convertToLocal = (
/*
* If country is the fictional demo country (Farajaland), use Zambian number format
*/

if (!mobileWithCountryCode) {
return
}
const phoneUtil = PhoneNumberUtil.getInstance()
const number = phoneUtil.parse(mobileWithCountryCode)
const countryCode = alpha3CountryCode
Expand All @@ -115,7 +119,9 @@ export const convertToLocal = (
if (!phoneUtil.isPossibleNumberString(mobileWithCountryCode, countryCode)) {
return
}
let nationalFormat = phoneUtil.format(number, PhoneNumberFormat.NATIONAL)
let nationalFormat = phoneUtil
.format(number, PhoneNumberFormat.NATIONAL)
.replace(/[^A-Z0-9]+/gi, '')

// This is a special case for countries that have a national prefix of 0
if (
Expand All @@ -124,7 +130,6 @@ export const convertToLocal = (
) {
nationalFormat = '0' + nationalFormat
}

return nationalFormat
}

Expand All @@ -138,8 +143,7 @@ export const localPhoneTransformer =
) => {
const fieldName = transformedFieldName || field.name
const msisdnPhone = get(queryData, fieldName as string) as unknown as string

const localPhone = convertToLocal(msisdnPhone)
const localPhone = convertToLocal(msisdnPhone, window.config.COUNTRY)

transformedData[sectionId][field.name] = localPhone
return transformedData
Expand Down

0 comments on commit fd4b0dc

Please sign in to comment.