Update libphonenumber-js
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
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 { useParams, useRouter } from "next/navigation"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { FormProvider, useForm } from "react-hook-form"
|
import { FormProvider, useForm } from "react-hook-form"
|
||||||
@@ -46,7 +49,7 @@ export default function Form({ user }: EditFormProps) {
|
|||||||
const { inputValue: phoneInput } = usePhoneInput({
|
const { inputValue: phoneInput } = usePhoneInput({
|
||||||
defaultCountry:
|
defaultCountry:
|
||||||
user.phoneNumber && isValidPhoneNumber(user.phoneNumber)
|
user.phoneNumber && isValidPhoneNumber(user.phoneNumber)
|
||||||
? parsePhoneNumber(user.phoneNumber).country?.toLowerCase()
|
? parsePhoneNumberWithError(user.phoneNumber).country?.toLowerCase()
|
||||||
: "se",
|
: "se",
|
||||||
forceDialCode: true,
|
forceDialCode: true,
|
||||||
value: user.phoneNumber,
|
value: user.phoneNumber,
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import "react-international-phone/style.css"
|
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 { TextField } from "react-aria-components"
|
||||||
import { useController, useFormContext, useWatch } from "react-hook-form"
|
import { useController, useFormContext, useWatch } from "react-hook-form"
|
||||||
import {
|
import {
|
||||||
@@ -59,7 +62,7 @@ export default function Phone({
|
|||||||
// If defaultPhoneNumber exists and is valid, parse it to get the country code,
|
// If defaultPhoneNumber exists and is valid, parse it to get the country code,
|
||||||
// otherwise set the default country from the lang.
|
// otherwise set the default country from the lang.
|
||||||
const defaultCountry = isValidPhoneNumber(defaultPhoneNumber)
|
const defaultCountry = isValidPhoneNumber(defaultPhoneNumber)
|
||||||
? parsePhoneNumber(defaultPhoneNumber).country?.toLowerCase()
|
? parsePhoneNumberWithError(defaultPhoneNumber).country?.toLowerCase()
|
||||||
: getDefaultCountryFromLang(lang)
|
: getDefaultCountryFromLang(lang)
|
||||||
|
|
||||||
const { country, handlePhoneValueChange, inputValue, setCountry } =
|
const { country, handlePhoneValueChange, inputValue, setCountry } =
|
||||||
|
|||||||
@@ -89,7 +89,7 @@
|
|||||||
"input-otp": "^1.4.2",
|
"input-otp": "^1.4.2",
|
||||||
"json-stable-stringify-without-jsonify": "^1.0.1",
|
"json-stable-stringify-without-jsonify": "^1.0.1",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"libphonenumber-js": "^1.10.60",
|
"libphonenumber-js": "^1.12.7",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"md5": "^2.3.0",
|
"md5": "^2.3.0",
|
||||||
"nanoid": "^5.1.5",
|
"nanoid": "^5.1.5",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
isPossiblePhoneNumber,
|
isPossiblePhoneNumber,
|
||||||
ParseError,
|
ParseError,
|
||||||
parsePhoneNumber,
|
parsePhoneNumberWithError,
|
||||||
validatePhoneNumberLength,
|
validatePhoneNumberLength,
|
||||||
} from "libphonenumber-js"
|
} from "libphonenumber-js"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
@@ -24,7 +24,7 @@ export function phoneValidator(
|
|||||||
.superRefine((value, ctx) => {
|
.superRefine((value, ctx) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
try {
|
try {
|
||||||
const phoneNumber = parsePhoneNumber(value)
|
const phoneNumber = parsePhoneNumberWithError(value)
|
||||||
if (phoneNumber) {
|
if (phoneNumber) {
|
||||||
if (isPossiblePhoneNumber(value, phoneNumber.country)) {
|
if (isPossiblePhoneNumber(value, phoneNumber.country)) {
|
||||||
return validatePhoneNumberLength(value, phoneNumber.country)
|
return validatePhoneNumberLength(value, phoneNumber.country)
|
||||||
|
|||||||
10
yarn.lock
10
yarn.lock
@@ -8483,7 +8483,7 @@ __metadata:
|
|||||||
json-sort-cli: "npm:^4.0.9"
|
json-sort-cli: "npm:^4.0.9"
|
||||||
json-stable-stringify-without-jsonify: "npm:^1.0.1"
|
json-stable-stringify-without-jsonify: "npm:^1.0.1"
|
||||||
jsonwebtoken: "npm:^9.0.2"
|
jsonwebtoken: "npm:^9.0.2"
|
||||||
libphonenumber-js: "npm:^1.10.60"
|
libphonenumber-js: "npm:^1.12.7"
|
||||||
lint-staged: "npm:^15.5.2"
|
lint-staged: "npm:^15.5.2"
|
||||||
lodash-es: "npm:^4.17.21"
|
lodash-es: "npm:^4.17.21"
|
||||||
material-symbols: "npm:^0.29.0"
|
material-symbols: "npm:^0.29.0"
|
||||||
@@ -17999,10 +17999,10 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"libphonenumber-js@npm:^1.10.60":
|
"libphonenumber-js@npm:^1.12.7":
|
||||||
version: 1.11.20
|
version: 1.12.7
|
||||||
resolution: "libphonenumber-js@npm:1.11.20"
|
resolution: "libphonenumber-js@npm:1.12.7"
|
||||||
checksum: 10c0/fb1010bfa5f8682dadfbd9608f76207510e13c456db96d0d534cf727efa2de005cafbb16d016046965894af0787bf567eb5a1a2688d7bb2d5f8b2eebc42437c6
|
checksum: 10c0/ac732b5e8bfe093b4c2aa470a69f52304ebe7cfefebe3ef902ba0cbbf2c159da00993cae0425c7e497961ca015d46082925f37a6c8626b07e98e1bb9e45414cb
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user