From 41aa4f26ad6fe50e2150e36bc3d3a3fa92debc40 Mon Sep 17 00:00:00 2001 From: Anton Gunnarsson Date: Tue, 6 May 2025 16:22:37 +0200 Subject: [PATCH] Update libphonenumber-js --- .../components/Forms/Edit/Profile/index.tsx | 7 +++++-- .../components/TempDesignSystem/Form/Phone/index.tsx | 7 +++++-- apps/scandic-web/package.json | 2 +- apps/scandic-web/utils/zod/phoneValidator.ts | 4 ++-- yarn.lock | 10 +++++----- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/apps/scandic-web/components/Forms/Edit/Profile/index.tsx b/apps/scandic-web/components/Forms/Edit/Profile/index.tsx index 28704a6f9..671fee147 100644 --- a/apps/scandic-web/components/Forms/Edit/Profile/index.tsx +++ b/apps/scandic-web/components/Forms/Edit/Profile/index.tsx @@ -1,6 +1,9 @@ "use client" import { zodResolver } from "@hookform/resolvers/zod" -import { isValidPhoneNumber, parsePhoneNumber } from "libphonenumber-js" +import { + isValidPhoneNumber, + parsePhoneNumberWithError, +} from "libphonenumber-js" import { useParams, useRouter } from "next/navigation" import { useEffect, useState } from "react" import { FormProvider, useForm } from "react-hook-form" @@ -46,7 +49,7 @@ export default function Form({ user }: EditFormProps) { const { inputValue: phoneInput } = usePhoneInput({ defaultCountry: user.phoneNumber && isValidPhoneNumber(user.phoneNumber) - ? parsePhoneNumber(user.phoneNumber).country?.toLowerCase() + ? parsePhoneNumberWithError(user.phoneNumber).country?.toLowerCase() : "se", forceDialCode: true, value: user.phoneNumber, diff --git a/apps/scandic-web/components/TempDesignSystem/Form/Phone/index.tsx b/apps/scandic-web/components/TempDesignSystem/Form/Phone/index.tsx index 721819940..cb7e18f8b 100644 --- a/apps/scandic-web/components/TempDesignSystem/Form/Phone/index.tsx +++ b/apps/scandic-web/components/TempDesignSystem/Form/Phone/index.tsx @@ -1,7 +1,10 @@ "use client" import "react-international-phone/style.css" -import { isValidPhoneNumber, parsePhoneNumber } from "libphonenumber-js" +import { + isValidPhoneNumber, + parsePhoneNumberWithError, +} from "libphonenumber-js" import { TextField } from "react-aria-components" import { useController, useFormContext, useWatch } from "react-hook-form" import { @@ -59,7 +62,7 @@ export default function Phone({ // If defaultPhoneNumber exists and is valid, parse it to get the country code, // otherwise set the default country from the lang. const defaultCountry = isValidPhoneNumber(defaultPhoneNumber) - ? parsePhoneNumber(defaultPhoneNumber).country?.toLowerCase() + ? parsePhoneNumberWithError(defaultPhoneNumber).country?.toLowerCase() : getDefaultCountryFromLang(lang) const { country, handlePhoneValueChange, inputValue, setCountry } = diff --git a/apps/scandic-web/package.json b/apps/scandic-web/package.json index a7ba642dd..24caf591f 100644 --- a/apps/scandic-web/package.json +++ b/apps/scandic-web/package.json @@ -89,7 +89,7 @@ "input-otp": "^1.4.2", "json-stable-stringify-without-jsonify": "^1.0.1", "jsonwebtoken": "^9.0.2", - "libphonenumber-js": "^1.10.60", + "libphonenumber-js": "^1.12.7", "lodash-es": "^4.17.21", "md5": "^2.3.0", "nanoid": "^5.1.5", diff --git a/apps/scandic-web/utils/zod/phoneValidator.ts b/apps/scandic-web/utils/zod/phoneValidator.ts index 2f2d72d3b..6a512d996 100644 --- a/apps/scandic-web/utils/zod/phoneValidator.ts +++ b/apps/scandic-web/utils/zod/phoneValidator.ts @@ -1,7 +1,7 @@ import { isPossiblePhoneNumber, ParseError, - parsePhoneNumber, + parsePhoneNumberWithError, validatePhoneNumberLength, } from "libphonenumber-js" import { z } from "zod" @@ -24,7 +24,7 @@ export function phoneValidator( .superRefine((value, ctx) => { if (value) { try { - const phoneNumber = parsePhoneNumber(value) + const phoneNumber = parsePhoneNumberWithError(value) if (phoneNumber) { if (isPossiblePhoneNumber(value, phoneNumber.country)) { return validatePhoneNumberLength(value, phoneNumber.country) diff --git a/yarn.lock b/yarn.lock index 5a9142591..148e7282a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8483,7 +8483,7 @@ __metadata: json-sort-cli: "npm:^4.0.9" json-stable-stringify-without-jsonify: "npm:^1.0.1" jsonwebtoken: "npm:^9.0.2" - libphonenumber-js: "npm:^1.10.60" + libphonenumber-js: "npm:^1.12.7" lint-staged: "npm:^15.5.2" lodash-es: "npm:^4.17.21" material-symbols: "npm:^0.29.0" @@ -17999,10 +17999,10 @@ __metadata: languageName: node linkType: hard -"libphonenumber-js@npm:^1.10.60": - version: 1.11.20 - resolution: "libphonenumber-js@npm:1.11.20" - checksum: 10c0/fb1010bfa5f8682dadfbd9608f76207510e13c456db96d0d534cf727efa2de005cafbb16d016046965894af0787bf567eb5a1a2688d7bb2d5f8b2eebc42437c6 +"libphonenumber-js@npm:^1.12.7": + version: 1.12.7 + resolution: "libphonenumber-js@npm:1.12.7" + checksum: 10c0/ac732b5e8bfe093b4c2aa470a69f52304ebe7cfefebe3ef902ba0cbbf2c159da00993cae0425c7e497961ca015d46082925f37a6c8626b07e98e1bb9e45414cb languageName: node linkType: hard