Merged in fix/phone-country-code-fix (pull request #2357)

fix: remove country code from prefilled phone input

Approved-by: Simon.Emanuelsson
This commit is contained in:
Christian Andolf
2025-06-13 11:01:40 +00:00
11 changed files with 62 additions and 45 deletions

View File

@@ -1,13 +1,8 @@
"use client"
import { zodResolver } from "@hookform/resolvers/zod"
import {
isValidPhoneNumber,
parsePhoneNumberWithError,
} from "libphonenumber-js"
import { useParams, useRouter } from "next/navigation"
import { useEffect, useState } from "react"
import { FormProvider, useForm } from "react-hook-form"
import { usePhoneInput } from "react-international-phone"
import { useIntl } from "react-intl"
import { type Lang, langToApiLang } from "@/constants/languages"
@@ -21,6 +16,7 @@ import ChangeNameDisclaimer from "@/components/MyPages/Profile/ChangeNameDisclai
import Button from "@/components/TempDesignSystem/Button"
import Title from "@/components/TempDesignSystem/Text/Title"
import { toast } from "@/components/TempDesignSystem/Toasts"
import usePhoneNumberParsing from "@/hooks/usePhoneNumberParsing"
import FormContent from "./FormContent"
import { type EditProfileSchema, editProfileSchema } from "./schema"
@@ -47,14 +43,7 @@ export default function Form({ user }: EditFormProps) {
*/
const [isValid, setIsValid] = useState(true)
const { inputValue: phoneInput } = usePhoneInput({
defaultCountry:
user.phoneNumber && isValidPhoneNumber(user.phoneNumber)
? parsePhoneNumberWithError(user.phoneNumber).country?.toLowerCase()
: "se",
forceDialCode: true,
value: user.phoneNumber,
})
const { phoneNumber, phoneNumberCC } = usePhoneNumberParsing(user.phoneNumber)
const methods = useForm<EditProfileSchema>({
defaultValues: {
@@ -67,7 +56,8 @@ export default function Form({ user }: EditFormProps) {
dateOfBirth: user.dateOfBirth,
email: user.email,
language: user.language ?? langToApiLang[lang],
phoneNumber: phoneInput,
phoneNumber: phoneNumber,
phoneNumberCC: phoneNumberCC,
password: "",
newPassword: "",
retypeNewPassword: "",

View File

@@ -34,6 +34,7 @@ export const editProfileSchema = z
editProfileErrors.PHONE_REQUIRED,
editProfileErrors.PHONE_REQUESTED
),
phoneNumberCC: z.string(),
password: z.string().optional(),
newPassword: z.literal("").optional().or(passwordValidator()),