"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { Loader2, Unlink } from "lucide-react"; export function DisconnectLinkedInButton() { const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const router = useRouter(); const handleDisconnect = async () => { if (!confirm("Are you sure you want to disconnect your LinkedIn account?")) return; setLoading(true); setError(null); try { const res = await fetch("/api/linkedin/disconnect", { method: "DELETE" }); const data = await res.json(); if (!res.ok) { setError(data.error ?? "Something went wrong"); return; } router.refresh(); } catch { setError("Failed to disconnect. Please try again."); } finally { setLoading(false); } }; return (
{error &&

{error}

}
); }