diff --git a/CHANGELOG.md b/CHANGELOG.md index b81f3d4c0d..fb28665b71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/client/src/forms/register/mappings/query/registration-mappings.test.ts b/packages/client/src/forms/register/mappings/query/registration-mappings.test.ts index d2c5293f40..e9153a3ee9 100644 --- a/packages/client/src/forms/register/mappings/query/registration-mappings.test.ts +++ b/packages/client/src/forms/register/mappings/query/registration-mappings.test.ts @@ -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') }) }) diff --git a/packages/client/src/forms/register/mappings/query/registration-mappings.ts b/packages/client/src/forms/register/mappings/query/registration-mappings.ts index c17758fbaa..3c3f2de432 100644 --- a/packages/client/src/forms/register/mappings/query/registration-mappings.ts +++ b/packages/client/src/forms/register/mappings/query/registration-mappings.ts @@ -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 = @@ -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