From 852f23f68f5420c0ca2f51171e2f7439db46896f Mon Sep 17 00:00:00 2001 From: villarley Date: Sat, 1 Feb 2025 21:13:15 -0600 Subject: [PATCH] fix: min updates --- .../app/user/edit-profile/my-profile/page.tsx | 53 +++++++------------ 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/apps/web/src/app/user/edit-profile/my-profile/page.tsx b/apps/web/src/app/user/edit-profile/my-profile/page.tsx index 6b72599..fc855ab 100644 --- a/apps/web/src/app/user/edit-profile/my-profile/page.tsx +++ b/apps/web/src/app/user/edit-profile/my-profile/page.tsx @@ -1,10 +1,8 @@ "use client"; -import { CameraIcon } from "@heroicons/react/24/outline"; import { zodResolver } from "@hookform/resolvers/zod"; import Button from "@repo/ui/button"; import InputField from "@repo/ui/form/inputField"; -import Image from "next/image"; import { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; @@ -23,19 +21,29 @@ type FormData = z.infer; function EditMyProfile() { const utils = api.useUtils(); const { t } = useTranslation(); - const [image, setImage] = useState(null); - const userId = "cm2wbxug00000kkm7tvhlujf2"; // Assume you have the logic to get the userId + const userId = "cm2wbxug00000kkm7tvhlujf2"; - const { data: user, isLoading } = api.user.getUser.useQuery({ - userId, + const { data: user, isLoading } = api.user.getUser.useQuery({ userId }); + + const { register, handleSubmit, control, reset } = useForm({ + resolver: zodResolver(schema), + defaultValues: { + fullName: "", + email: "", + physicalAddress: "", + }, }); useEffect(() => { - if (user?.image) { - setImage(user.image); + if (user) { + reset({ + fullName: user.name ?? "", + email: user.email ?? "", + physicalAddress: user.physicalAddress ?? "", + }); } - }, [user]); + }, [user, reset]); const { mutate: updateProfile } = api.user.updateUserProfile.useMutation({ onSuccess: async () => { @@ -48,15 +56,6 @@ function EditMyProfile() { }, }); - const { register, handleSubmit, control } = useForm({ - resolver: zodResolver(schema), - defaultValues: { - fullName: user?.name ?? "", - email: user?.email ?? "", - physicalAddress: user?.physicalAddress ?? "", - }, - }); - const onSubmit = (data: FormData) => { void updateProfile({ userId, @@ -78,32 +77,20 @@ function EditMyProfile() {
{ - void register("fullName").onChange({ target: { value } }); - }} + name="fullName" control={control} className="mb-4" /> { - void register("email").onChange({ target: { value } }); - }} + name="email" control={control} className="mb-4" - // disabled inputClassName="cursor-not-allowed" /> { - void register("physicalAddress").onChange({ - target: { value }, - }); - }} + name="physicalAddress" control={control} className="mb-4" />