import React, { useCallback, useEffect, useState } from 'react'; import { Mail, RefreshCw, Loader2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { apiFetch } from '@/lib/api'; import { cn } from '@/lib/utils'; export default function ConnectMailboxSettings() { 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/mailbox/campaign-defaults'); const d = r.ok ? await r.json() : {}; setAccounts(d.accounts || []); setDefaultRefId(d.default_mailbox_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/mailbox/hosted-link', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ label: 'Mailbox', }), }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.detail || 'Could not start mailbox connect'); if (data.url) window.location.href = data.url; } catch (e) { alert(e.message || 'Connect failed'); } finally { setBusy(false); } }; return (
Connect Mailbox
{loading ? (
) : accounts.length === 0 ? (

Connected mailboxes: 0

) : (

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

)}
); }