"use client"; import { useState } from "react"; import { Linkedin, Loader2 } from "lucide-react"; export function ConnectLinkedInButton() { const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleConnect = async () => { setLoading(true); setError(null); try { const res = await fetch("/api/linkedin/connect", { method: "POST" }); const data = await res.json(); if (!res.ok) { setError(data.error ?? "Something went wrong"); return; } window.location.href = data.url; } catch { setError("Failed to initiate connection. Please try again."); } finally { setLoading(false); } }; return (
{error &&

{error}

}
); }