Update libphonenumber-js
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 } =
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user