"use client"; import InputField from "@/components/global/form-field/input-field"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Button } from "@/components/ui/button"; import { Separator } from "@/components/ui/separator"; import { useUpdateProfileMutation } from "@/features/auth/queries/auth.mutations"; import { profileZodSchema, type IProfilePayload, } from "@/features/auth/validators/profile.validator"; import { zodResolver } from "@hookform/resolvers/zod"; import { Camera, Loader2, Lock } from "lucide-react"; import { useState } from "react"; import { FormProvider, useForm, useWatch } from "react-hook-form"; import { toast } from "sonner"; import ChangePasswordDialog from "./change-password-dialog"; interface User { id: string; name?: string | null; email?: string | null; image?: string | null; role?: string; createdAt?: Date | string; } interface ProfileFormProps { user: User; } export default function ProfileForm({ user }: ProfileFormProps) { const mutation = useUpdateProfileMutation(); const [showPasswordDialog, setShowPasswordDialog] = useState(false); const form = useForm({ mode: "onTouched", resolver: zodResolver(profileZodSchema), defaultValues: { name: user.name || "", image: user.image || "", }, }); const imageValue = useWatch({ control: form.control, name: "image" }); const nameValue = useWatch({ control: form.control, name: "name" }); async function onSubmit(values: IProfilePayload) { try { await mutation.mutateAsync(values); } catch {} } const handleImageUpload = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; if (file.size > 2 * 1024 * 1024) { toast.error("Image size must be less than 2MB"); return; } const reader = new FileReader(); reader.onloadend = () => { form.setValue("image", reader.result as string); toast.info("Image loaded. Click 'Save Changes' to update."); }; reader.readAsDataURL(file); }; return (

Personal Information

Update your personal details and profile picture

{nameValue?.[0]?.toUpperCase() || "U"}

Profile Picture

JPG, PNG or GIF. Max size 2MB.

Security

Manage your password and account security

Password

Last changed recently

); }