"use client" import { useState } from "react" import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import { Loader2, User, Save } from "lucide-react" import { Session } from "next-auth" import { toast } from "sonner" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { updateProfileSchema, type UpdateProfileInput } from "@/lib/validation" interface ProfileFormProps { user: { name?: string | null email?: string | null } update: (data?: { name?: string | null; email?: string | null; image?: string | null }) => Promise } export function ProfileForm({ user, update }: ProfileFormProps) { const form = useForm({ resolver: zodResolver(updateProfileSchema), defaultValues: { name: user.name || "", email: user.email || "", }, }) const onSubmit = async (data: UpdateProfileInput) => { try { const response = await fetch("/api/user/profile", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data), }) const result = await response.json() if (!response.ok) { toast.error(result.error || "Failed to update profile") return } await update({ name: data.name, email: data.email, }) toast.success("Profile updated successfully!") } catch { toast.error("An unexpected error occurred") } } return ( Profile Information Update your personal information
( Full Name )} /> ( Email Address )} />
) }