import { useCallback, useState } from "react"; import { AnimatePresence } from "framer-motion"; import { Browser, Megaphone, Plus } from "@phosphor-icons/react"; import type { BrowserActionRecord, SocialAccountRecord, SocialPlatform } from "@shared/types"; import { ActionButton } from "../ui"; import { useT } from "../../i18n"; import { AccountCard } from "./AccountCard"; import { AddAccountDialog } from "./AddAccountDialog"; import { ActionHistory } from "./ActionHistory"; interface SocialPanelProps { accounts: SocialAccountRecord[]; actions: BrowserActionRecord[]; agents: Array<{ id: string; name: string }>; companyId: string; onSave: (input: { companyId: string; platform: SocialPlatform; accountName: string; displayName: string; requireApproval: boolean; }) => Promise; onDelete: (id: string) => Promise; onLogin: (accountId: string) => Promise; onOpenPath: (path: string) => Promise; onCancelAction: (actionId: string) => Promise; onNavigate: (section: "tasks" | "approvals", entityId: string) => void; } export function SocialAccountsPanel({ accounts, actions, agents, companyId, onSave, onDelete, onLogin, onOpenPath, onCancelAction, onNavigate, }: SocialPanelProps) { const t = useT(); const [showAddDialog, setShowAddDialog] = useState(false); const [activeTab, setActiveTab] = useState<"accounts" | "history">("accounts"); const handleAdd = useCallback(async (platform: SocialPlatform, accountName: string, displayName: string, requireApproval: boolean) => { await onSave({ companyId, platform, accountName, displayName, requireApproval }); setShowAddDialog(false); }, [companyId, onSave]); return (

{t("social.socialMedia")}

{accounts.length} account{accounts.length !== 1 ? "s" : ""} connected

setShowAddDialog(true)} icon={Plus} tone="accent" />
How it works
Add your social media accounts here. Click "Login" to open a browser where you can sign in. Your session is saved locally so marketing agents can post content, reply to users, and browse feeds using browser automation. All actions are logged and can require Board approval.
{activeTab === "accounts" ? ( accounts.length === 0 ? (
{t("social.noAccounts")}
{t("social.noAccountsDesc")}
setShowAddDialog(true)} icon={Plus} tone="accent" />
) : (
{accounts.map((account) => ( void onLogin(account.id)} onDelete={() => void onDelete(account.id)} /> ))}
) ) : ( )} {showAddDialog ? ( void handleAdd(platform, accountName, displayName, requireApproval)} onClose={() => setShowAddDialog(false)} /> ) : null}
); }