fix: now parses phone number before submitting on edit profile and signup
This commit is contained in:
@@ -5,7 +5,11 @@ import { useEffect, useState } from "react"
|
||||
import { FormProvider, useForm } from "react-hook-form"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { type Lang, langToApiLang } from "@/constants/languages"
|
||||
import {
|
||||
getDefaultCountryFromLang,
|
||||
type Lang,
|
||||
langToApiLang,
|
||||
} from "@/constants/languages"
|
||||
import { logout } from "@/constants/routes/handleAuth"
|
||||
import { profile } from "@/constants/routes/myPages"
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
@@ -17,6 +21,7 @@ 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 { formatPhoneNumber } from "@/utils/phone"
|
||||
|
||||
import FormContent from "./FormContent"
|
||||
import { type EditProfileSchema, editProfileSchema } from "./schema"
|
||||
@@ -57,7 +62,7 @@ export default function Form({ user }: EditFormProps) {
|
||||
email: user.email,
|
||||
language: user.language ?? langToApiLang[lang],
|
||||
phoneNumber: phoneNumber,
|
||||
phoneNumberCC: phoneNumberCC,
|
||||
phoneNumberCC: phoneNumberCC || getDefaultCountryFromLang(lang),
|
||||
password: "",
|
||||
newPassword: "",
|
||||
retypeNewPassword: "",
|
||||
@@ -71,7 +76,8 @@ export default function Form({ user }: EditFormProps) {
|
||||
|
||||
async function handleSubmit(data: EditProfileSchema) {
|
||||
const isPasswordChanged = !!data.newPassword
|
||||
const response = await editProfile(data)
|
||||
const phoneNumber = formatPhoneNumber(data.phoneNumber, data.phoneNumberCC)
|
||||
const response = await editProfile({ ...data, phoneNumber })
|
||||
switch (response.status) {
|
||||
case Status.error:
|
||||
if (response.issues?.length) {
|
||||
|
||||
Reference in New Issue
Block a user