import React, { useCallback, useEffect, useState } from 'react'; import { Link2, RefreshCw, Loader2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { apiFetch } from '@/lib/api'; import { cn } from '@/lib/utils'; export default function LinkedInConnectSettings() { const [loading, setLoading] = useState(true); const [busy, setBusy] = useState(false); const [accounts, setAccounts] = useState([]); const [defaultRefId, setDefaultRefId] = useState(null); const load = useCallback(async () => { setLoading(true); try { const r = await apiFetch('/api/unipile/linkedin/campaign-defaults'); const d = r.ok ? await r.json() : {}; setAccounts(d.accounts || []); setDefaultRefId(d.default_unipile_account_ref_id ?? null); } catch { setAccounts([]); } finally { setLoading(false); } }, []); useEffect(() => { load(); }, [load]); const connectAccount = async () => { setBusy(true); try { const res = await apiFetch('/api/unipile/linkedin/hosted-link', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ label: 'LinkedIn account', }), }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.detail || 'Could not start LinkedIn connect'); if (data.url) window.location.href = data.url; } catch (e) { alert(e.message || 'Connect failed'); } finally { setBusy(false); } }; return (
Connect LinkedIn
{loading ? (
) : accounts.length === 0 ? (

Connected accounts: 0

) : (

Connected accounts ({accounts.length}) — default for LinkedIn sequence steps

)}
); }