import { useEffect, useState } from "react"; import { RefreshCw, Instagram, Facebook } from "lucide-react"; import { api } from "../api.js"; import { Button, cx, Dialog, Empty, ErrorNote, Field, fmt, Spinner } from "../ui.jsx"; /** Pick a Facebook Page the agency can manage → create the client's folder, brand files and link. */ export default function AddClientDialog({ open, onClose, onAdded }) { const [accounts, setAccounts] = useState(null); const [error, setError] = useState(null); const [picked, setPicked] = useState(null); const [name, setName] = useState(""); const [runAudit, setRunAudit] = useState(true); const [busy, setBusy] = useState(false); const load = (refresh) => { setAccounts(null); setError(null); api(`/api/accounts/unlinked${refresh ? "?refresh=1" : ""}`).then((r) => setAccounts(r.accounts)).catch(setError); }; useEffect(() => { if (open) { load(false); setPicked(null); setName(""); } }, [open]); const add = async () => { setBusy(true); setError(null); try { const r = await api("/api/clients", { method: "POST", body: { accountId: picked.account_id, name, runAudit } }); onClose(); onAdded?.(r.client); } catch (e) { setError(e); } finally { setBusy(false); } }; return ( } >

Pages connected to the agency's Meta account that don't have a client folder yet. Connect new Pages in Meta Business Suite first.

{!accounts && !error ? ( ) : accounts?.length === 0 ? ( Add the new business's Page to the agency's Meta Business account, then check again. ) : (
    {accounts?.map((a) => (
  • ))}
)} {picked && (
setName(e.target.value)} />
)}
); }