From d49b29569b8f0fbcdbbdefb6237814ea9b21200c Mon Sep 17 00:00:00 2001 From: areski Date: Mon, 30 Nov 2020 15:08:11 +0100 Subject: [PATCH 1/4] [fix](sessions) fix formatting in getFullNumber to work nicely with international number --- src/util/sessions.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/util/sessions.ts b/src/util/sessions.ts index 4e34edb..3bedf76 100644 --- a/src/util/sessions.ts +++ b/src/util/sessions.ts @@ -93,12 +93,19 @@ export const getFullNumber = (number: string) => { if (number.length < 10) { return number } + let fullNumber = `${number}` + // Remove leading + if already set + if (fullNumber.startsWith('+')) { + fullNumber = fullNumber.substring(1) + } + // Add default country code // @ts-ignore - let fullNumber = `+${phoneStore.getState().sipAccounts.sipAccount._config.defaultCountryCode}${number}` - if (number.includes('+') && number.length === 10) { - fullNumber = `${number}` + const countrycode = phoneStore.getState().sipAccounts.sipAccount._config.defaultCountryCode + fullNumber = `${countrycode}${number}` + if (!fullNumber.startsWith('+')) { + fullNumber = `+${number}` } - console.log(fullNumber) + console.log(`fullNumber: ${fullNumber}`) return fullNumber } From 416ef77a199306845d9db17351aa755bc4c77d5e Mon Sep 17 00:00:00 2001 From: areski Date: Mon, 30 Nov 2020 15:19:19 +0100 Subject: [PATCH 2/4] [fix](sessions) simplify getFullNumber --- src/util/sessions.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/util/sessions.ts b/src/util/sessions.ts index 3bedf76..3ea17d5 100644 --- a/src/util/sessions.ts +++ b/src/util/sessions.ts @@ -101,10 +101,7 @@ export const getFullNumber = (number: string) => { // Add default country code // @ts-ignore const countrycode = phoneStore.getState().sipAccounts.sipAccount._config.defaultCountryCode - fullNumber = `${countrycode}${number}` - if (!fullNumber.startsWith('+')) { - fullNumber = `+${number}` - } + fullNumber = `+${countrycode}${fullNumber}` console.log(`fullNumber: ${fullNumber}`) return fullNumber } From 5e6c1e9147fb55a3b7a0f71731e6bdf8ea3fe55e Mon Sep 17 00:00:00 2001 From: areski Date: Thu, 3 Dec 2020 15:05:49 +0100 Subject: [PATCH 3/4] [fix](sessions) add sanitizePhoneNumber --- src/util/sessions.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/util/sessions.ts b/src/util/sessions.ts index 3ea17d5..defc253 100644 --- a/src/util/sessions.ts +++ b/src/util/sessions.ts @@ -89,6 +89,10 @@ export class SessionStateHandler { } } +const sanitizePhoneNumber = (number: string) => { + return number.replace(/[^\d+]/g, '') +} + export const getFullNumber = (number: string) => { if (number.length < 10) { return number @@ -101,8 +105,11 @@ export const getFullNumber = (number: string) => { // Add default country code // @ts-ignore const countrycode = phoneStore.getState().sipAccounts.sipAccount._config.defaultCountryCode - fullNumber = `+${countrycode}${fullNumber}` + + // add + & sanitize phone number to remove parentheses, space & dash + fullNumber = sanitizePhoneNumber(`+${countrycode}${fullNumber}`) console.log(`fullNumber: ${fullNumber}`) + return fullNumber } From f3a51e278306ee5ee9356433db086a4a55b9483a Mon Sep 17 00:00:00 2001 From: areski Date: Thu, 3 Dec 2020 15:34:14 +0100 Subject: [PATCH 4/4] [fix](sessions) ensure we remove any leading space before + --- src/util/sessions.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/util/sessions.ts b/src/util/sessions.ts index defc253..7b26314 100644 --- a/src/util/sessions.ts +++ b/src/util/sessions.ts @@ -98,6 +98,9 @@ export const getFullNumber = (number: string) => { return number } let fullNumber = `${number}` + // sanitize phone number to remove parentheses, space & dash + fullNumber = sanitizePhoneNumber(fullNumber) + // Remove leading + if already set if (fullNumber.startsWith('+')) { fullNumber = fullNumber.substring(1) @@ -106,8 +109,7 @@ export const getFullNumber = (number: string) => { // @ts-ignore const countrycode = phoneStore.getState().sipAccounts.sipAccount._config.defaultCountryCode - // add + & sanitize phone number to remove parentheses, space & dash - fullNumber = sanitizePhoneNumber(`+${countrycode}${fullNumber}`) + fullNumber = `+${countrycode}${fullNumber}` console.log(`fullNumber: ${fullNumber}`) return fullNumber