refactor: deprecate google-phonenumberlib

This commit is contained in:
Rafael 2024-12-01 08:54:10 +00:00
parent 3ac5ec6335
commit 676d3e439e
3 changed files with 12 additions and 28 deletions

View file

@ -34,12 +34,11 @@
"downshift": "3.3.4",
"file-saver": "2.0.2",
"formik": "2.2.0",
"google-libphonenumber": "^3.2.22",
"graphql": "^14.5.8",
"graphql-tag": "^2.12.6",
"jss-plugin-extend": "^10.0.0",
"jszip": "^3.6.0",
"libphonenumber-js": "^1.7.50",
"libphonenumber-js": "^1.11.15",
"match-sorter": "^4.2.0",
"pretty-ms": "^2.1.0",
"qrcode.react": "0.9.3",
@ -13266,14 +13265,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/google-libphonenumber": {
"version": "3.2.22",
"resolved": "https://registry.npmjs.org/google-libphonenumber/-/google-libphonenumber-3.2.22.tgz",
"integrity": "sha512-lzEllxWc05n/HEv75SsDrA7zdEVvQzTZimItZm/TZ5XBs7cmx2NJmSlA5I0kZbdKNu8GFETBhSpo+SOhx0JslA==",
"engines": {
"node": ">=0.10"
}
},
"node_modules/gopd": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
@ -17711,9 +17702,10 @@
}
},
"node_modules/libphonenumber-js": {
"version": "1.9.10",
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.9.10.tgz",
"integrity": "sha512-XyBYwt1dQCc9emeb78uCqJv9qy9tJQsg6vYDeJt37dwBYiZga8z0rHI5dcrn3aFKz9C5Nn9azaRBC+wmW91FfQ=="
"version": "1.11.15",
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.11.15.tgz",
"integrity": "sha512-M7+rtYi9l5RvMmHyjyoF3BHHUpXTYdJ0PezZGHNs0GyW1lO+K7jxlXpbdIb7a56h0nqLYdjIw+E+z0ciGaJP7g==",
"license": "MIT"
},
"node_modules/lie": {
"version": "3.3.0",

View file

@ -27,12 +27,11 @@
"downshift": "3.3.4",
"file-saver": "2.0.2",
"formik": "2.2.0",
"google-libphonenumber": "^3.2.22",
"graphql": "^14.5.8",
"graphql-tag": "^2.12.6",
"jss-plugin-extend": "^10.0.0",
"jszip": "^3.6.0",
"libphonenumber-js": "^1.7.50",
"libphonenumber-js": "^1.11.15",
"match-sorter": "^4.2.0",
"pretty-ms": "^2.1.0",
"qrcode.react": "0.9.3",

View file

@ -1,6 +1,6 @@
import { makeStyles } from '@material-ui/core/styles'
import { Field, Form, Formik } from 'formik'
import { PhoneNumberFormat, PhoneNumberUtil } from 'google-libphonenumber'
import { parsePhoneNumberWithError } from 'libphonenumber-js'
import * as R from 'ramda'
import React from 'react'
import ErrorMessage from 'src/components/ErrorMessage'
@ -33,8 +33,6 @@ const styles = {
}
}
const pnUtilInstance = PhoneNumberUtil.getInstance()
const getValidationSchema = countryCodes =>
Yup.object().shape({
phoneNumber: Yup.string()
@ -42,8 +40,8 @@ const getValidationSchema = countryCodes =>
.test('is-valid-number', 'That is not a valid phone number', value => {
try {
const validMap = R.map(it => {
const number = pnUtilInstance.parseAndKeepRawInput(value, it)
return pnUtilInstance.isValidNumber(number)
const number = parsePhoneNumberWithError(value, it)
return number.isValid()
}, countryCodes)
return R.any(it => it === true, validMap)
@ -54,16 +52,11 @@ const getValidationSchema = countryCodes =>
const formatPhoneNumber = (countryCodes, numberStr) => {
const matchedCountry = R.find(it => {
const number = pnUtilInstance.parseAndKeepRawInput(numberStr, it)
return pnUtilInstance.isValidNumber(number)
const number = parsePhoneNumberWithError(numberStr, it)
return number.isValid()
}, countryCodes)
const matchedNumber = pnUtilInstance.parseAndKeepRawInput(
numberStr,
matchedCountry
)
return pnUtilInstance.format(matchedNumber, PhoneNumberFormat.E164)
return parsePhoneNumberWithError(numberStr, matchedCountry).number
}
const initialValues = {