diff --git a/CHANGELOG.md b/CHANGELOG.md index b81f3d4c0d..5046db7f61 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 + +- 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 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 fe8cc9fe7d..f30a42276e 100644 --- a/packages/client/src/forms/register/mappings/query/registration-mappings.ts +++ b/packages/client/src/forms/register/mappings/query/registration-mappings.ts @@ -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 @@ -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 ( @@ -124,7 +130,6 @@ export const convertToLocal = ( ) { nationalFormat = '0' + nationalFormat } - return nationalFormat } @@ -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