From 676d3e439e138e005cc105320a70ef72a9038b2b Mon Sep 17 00:00:00 2001 From: Rafael Date: Sun, 1 Dec 2024 08:54:10 +0000 Subject: [PATCH] refactor: deprecate google-phonenumberlib --- new-lamassu-admin/package-lock.json | 18 +++++------------- new-lamassu-admin/package.json | 3 +-- .../components/CreateCustomerModal.jsx | 19 ++++++------------- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/new-lamassu-admin/package-lock.json b/new-lamassu-admin/package-lock.json index 21a07601..fa2c71db 100644 --- a/new-lamassu-admin/package-lock.json +++ b/new-lamassu-admin/package-lock.json @@ -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", diff --git a/new-lamassu-admin/package.json b/new-lamassu-admin/package.json index fbbf6a5a..7d289d67 100644 --- a/new-lamassu-admin/package.json +++ b/new-lamassu-admin/package.json @@ -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", diff --git a/new-lamassu-admin/src/pages/Customers/components/CreateCustomerModal.jsx b/new-lamassu-admin/src/pages/Customers/components/CreateCustomerModal.jsx index 49447bbd..6e836edf 100644 --- a/new-lamassu-admin/src/pages/Customers/components/CreateCustomerModal.jsx +++ b/new-lamassu-admin/src/pages/Customers/components/CreateCustomerModal.jsx @@ -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 = {