"use client"; import { useState } from "react"; import { Loader2 } from "lucide-react"; export function GenerateButton({ userId }: { userId: string }) { const [loading, setLoading] = useState(false); const handleGenerate = async () => { setLoading(true); try { const res = await fetch("/api/recommendations/generate", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ userId }), }); if (!res.ok) { const error = await res.json(); alert(`Error: ${error.error}`); } else { alert("Recommendation generated successfully! Check Pending Approvals."); // In a real app, we'd revalidate the path or update state window.location.reload(); } } catch (error) { console.error(error); alert("Failed to generate recommendation."); } finally { setLoading(false); } }; return ( ); }