"use client"; import { useActionState, useEffect, useRef } from "react"; import { useRouter } from "next/navigation"; import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { updateProfile, type ActionResult } from "@/actions/profile"; import { toast } from "sonner"; import type { AppUser } from "@/lib/types"; const initial: ActionResult = { ok: false, error: "" }; export function ProfileForm({ user }: { user: AppUser }) { const router = useRouter(); const [state, action, pending] = useActionState(updateProfile, initial); const ref = useRef(null); useEffect(() => { if (state.ok) { toast.success("Profile saved"); router.refresh(); } else if (state.error) { toast.error(state.error); } }, [state, router]); return ( Profile
); }