Skip to content
Snippets Groups Projects
Verified Commit 8ee96ce5 authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

Format phone number correctly before submitting

Instead of manually putting together the phone number and hoping we get
it right, we instead format the number using the phonenumbers library.
This library is already in use for validation, making it the obvious
choice. This means that the backend will only receive E.164 formatted
phonenumbers from now on. In addition, we now ensure that the number is
in fact a mobile phone number.
parent 72970889
No related branches found
No related tags found
1 merge request!405Format phone number correctly before submitting
Pipeline #205511 passed
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
"i18next": "^21.3.3", "i18next": "^21.3.3",
"i18next-browser-languagedetector": "^6.1.2", "i18next-browser-languagedetector": "^6.1.2",
"i18next-http-backend": "^1.3.1", "i18next-http-backend": "^1.3.1",
"libphonenumber-js": "^1.9.35", "libphonenumber-js": "^1.10.28",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"react": "^17.0.2", "react": "^17.0.2",
"react-cookie": "^4.1.1", "react-cookie": "^4.1.1",
...@@ -15086,9 +15086,9 @@ ...@@ -15086,9 +15086,9 @@
} }
}, },
"node_modules/libphonenumber-js": { "node_modules/libphonenumber-js": {
"version": "1.9.39", "version": "1.10.28",
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.9.39.tgz", "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.28.tgz",
"integrity": "sha512-TxYz/Ii7mjkocKGKmFHhsTAvvcxr4AY3yUlZzZ2z7HC4DPRrNlzJ9n32/SMogqsyFOXLMXQPCkCInNRbiVaEPA==" "integrity": "sha512-1eAgjLrZA0+2Wgw4hs+4Q/kEBycxQo8ZLYnmOvZ3AlM8ImAVAJgDPlZtISLEzD1vunc2q8s2Pn7XwB7I8U3Kzw=="
}, },
"node_modules/lines-and-columns": { "node_modules/lines-and-columns": {
"version": "1.1.6", "version": "1.1.6",
...@@ -35325,9 +35325,9 @@ ...@@ -35325,9 +35325,9 @@
} }
}, },
"libphonenumber-js": { "libphonenumber-js": {
"version": "1.9.39", "version": "1.10.28",
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.9.39.tgz", "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.28.tgz",
"integrity": "sha512-TxYz/Ii7mjkocKGKmFHhsTAvvcxr4AY3yUlZzZ2z7HC4DPRrNlzJ9n32/SMogqsyFOXLMXQPCkCInNRbiVaEPA==" "integrity": "sha512-1eAgjLrZA0+2Wgw4hs+4Q/kEBycxQo8ZLYnmOvZ3AlM8ImAVAJgDPlZtISLEzD1vunc2q8s2Pn7XwB7I8U3Kzw=="
}, },
"lines-and-columns": { "lines-and-columns": {
"version": "1.1.6", "version": "1.1.6",
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
"i18next": "^21.3.3", "i18next": "^21.3.3",
"i18next-browser-languagedetector": "^6.1.2", "i18next-browser-languagedetector": "^6.1.2",
"i18next-http-backend": "^1.3.1", "i18next-http-backend": "^1.3.1",
"libphonenumber-js": "^1.9.35", "libphonenumber-js": "^1.10.28",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"react": "^17.0.2", "react": "^17.0.2",
"react-cookie": "^4.1.1", "react-cookie": "^4.1.1",
......
...@@ -5,6 +5,7 @@ import { ...@@ -5,6 +5,7 @@ import {
CountryCode, CountryCode,
getCountries, getCountries,
getCountryCallingCode, getCountryCallingCode,
parsePhoneNumber,
} from 'libphonenumber-js' } from 'libphonenumber-js'
import format from 'date-fns/format' import format from 'date-fns/format'
import parse from 'date-fns/parse' import parse from 'date-fns/parse'
...@@ -236,9 +237,8 @@ export default function GuestRegister() { ...@@ -236,9 +237,8 @@ export default function GuestRegister() {
const payload: any = { const payload: any = {
person: {}, person: {},
} }
payload.person.private_mobile = `+${getCountryCallingCode( const parsedPhone = parsePhoneNumber(registerData.mobilePhone, registerData.mobilePhoneCountry as CountryCode)
registerData.mobilePhoneCountry as CountryCode payload.person.private_mobile = parsedPhone.format('E.164')
)}${registerData.mobilePhone}`
if (initialGuestData !== null) { if (initialGuestData !== null) {
// Only include the fields if they have actually changed. Could also send them back to the // Only include the fields if they have actually changed. Could also send them back to the
......
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
Consent, Consent,
FetchedConsent, FetchedConsent,
} from 'interfaces' } from 'interfaces'
import { isValidPhoneNumber, parsePhoneNumber } from 'libphonenumber-js' import { isValidPhoneNumber, parsePhoneNumber } from 'libphonenumber-js/mobile'
import parse from 'date-fns/parse' import parse from 'date-fns/parse'
import { parseInt } from 'lodash' import { parseInt } from 'lodash'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment