"use client"; import { useState } from "react"; import { Loader2 } from "lucide-react"; import { toast } from "@/lib/toast"; 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(); toast.error(`Error: ${error.error}`); } else { toast.success( "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); toast.error("Failed to generate recommendation."); } finally { setLoading(false); } }; return ( ); }