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 issue with formatting national phone numbers for countries with a '0' national prefix #8318

Merged
merged 4 commits into from
Jan 16, 2025
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: 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

- For countries where local phone numbers start with 0, we now ensure the prefix remains unchanged when converting to and from the international format.

## 1.6.2 Release candidate

### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ describe('phone number conversion from international format back to local format
expect(convertToLocal('+260211000000', 'ZMB')).toBe('0211000000')
expect(convertToLocal('+358504700715', 'FIN')).toBe('0504700715')
expect(convertToLocal('+237666666666', 'CMR')).toBe('666666666')
expect(convertToLocal('+8801700000000', 'BGD')).toBe('01700000000')
expect(convertToLocal('+260211000000')).toBe('0211000000')
expect(convertToLocal('+358504700715')).toBe('0504700715')
expect(convertToLocal('+237666666666')).toBe('666666666')
expect(convertToLocal('+8801700000000')).toBe('01700000000')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,36 @@ export const certificateDateTransformer =

export const convertToLocal = (
mobileWithCountryCode: string,
alpha3CountryCode: string
alpha3CountryCode?: string
) => {
/*
* If country is the fictional demo country (Farajaland), use Zambian number format
*/

const countryCode = countryAlpha3toAlpha2(alpha3CountryCode)
const phoneUtil = PhoneNumberUtil.getInstance()
const number = phoneUtil.parse(mobileWithCountryCode)
const countryCode = alpha3CountryCode
? countryAlpha3toAlpha2(alpha3CountryCode)
: phoneUtil.getRegionCodeForNumber(number)

if (!countryCode) {
return
}

const phoneUtil = PhoneNumberUtil.getInstance()

if (!phoneUtil.isPossibleNumberString(mobileWithCountryCode, countryCode)) {
return
}
const number = phoneUtil.parse(mobileWithCountryCode, countryCode)

return phoneUtil
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 (
phoneUtil.getNddPrefixForRegion(countryCode, true) === '0' &&
!nationalFormat.startsWith('0')
) {
nationalFormat = '0' + nationalFormat
}
return nationalFormat
}

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

if (!msisdnPhone) {
return transformedData
}
const localPhone = convertToLocal(msisdnPhone, window.config.COUNTRY)

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