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 bb6b96d..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 = "1"; // 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,31 +56,15 @@ 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, name: data.fullName, + email: data.email, physicalAddress: data.physicalAddress, - image: image ?? undefined, }); }; - const handleImageUpload = () => { - void (async () => { - alert(t("implement_image_upload")); - setImage(null); - })(); - }; - return ( {t("loading")} ) : ( <> -
-
- {image ? ( - {t("profile_image")} - ) : ( -
- {t("no_image")} -
- )} -
- -
-
{ - 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" /> diff --git a/apps/web/src/server/api/routers/user.ts b/apps/web/src/server/api/routers/user.ts index 0d71cdb..adbfcfa 100644 --- a/apps/web/src/server/api/routers/user.ts +++ b/apps/web/src/server/api/routers/user.ts @@ -17,7 +17,6 @@ export const userRouter = createTRPCRouter({ name: z.string().optional().optional(), email: z.string().email().optional(), physicalAddress: z.string().optional(), - image: z.string().optional(), }), ) .mutation(async ({ ctx, input }) => { diff --git a/bun.lockb b/bun.lockb index 8e812ac..e68faec 100755 Binary files a/bun.lockb and b/bun.lockb differ