diff --git a/dashboard/src/App.jsx b/dashboard/src/App.jsx index 2bc71f4..ceacfa6 100644 --- a/dashboard/src/App.jsx +++ b/dashboard/src/App.jsx @@ -96,7 +96,7 @@ const ProfileNetworkIcons = ({ profile, size = 12 }) => ( ); -const UserProfileSelector = ({ profiles, selectedUserId, onSelect }) => { +const UserProfileSelector = ({ profiles, selectedUserId, onSelect, onConnect }) => { const [isOpen, setIsOpen] = useState(false); if (!profiles || profiles.length === 0) return null; @@ -163,6 +163,17 @@ const UserProfileSelector = ({ profiles, selectedUserId, onSelect }) => { ))} + {/* For managed users this dropdown otherwise does nothing (one profile, + nothing to switch) — its real job is being the door to connecting + the greyed-out networks it displays. */} + {onConnect && ( + + )} )} @@ -881,6 +892,7 @@ function App() { profiles={userProfiles} selectedUserId={uploadUserId} onSelect={setUploadUserId} + onConnect={isManaged ? handleConnectSocials : undefined} /> )} diff --git a/dashboard/src/components/AccountPage.jsx b/dashboard/src/components/AccountPage.jsx index 524bceb..414bd95 100644 --- a/dashboard/src/components/AccountPage.jsx +++ b/dashboard/src/components/AccountPage.jsx @@ -4,6 +4,7 @@ import { useAuth } from '../contexts/AuthContext'; import { apiJson } from '../lib/api'; import { track } from '../lib/analytics'; import ApiKeysCard from './ApiKeysCard'; +import SocialAnalyticsCard from './SocialAnalyticsCard'; const fmt1 = (n) => Math.round((n || 0) * 10) / 10; @@ -181,6 +182,8 @@ export default function AccountPage() { + + {topups.length > 0 && (

Buy more minutes

diff --git a/dashboard/src/components/SocialAnalyticsCard.jsx b/dashboard/src/components/SocialAnalyticsCard.jsx new file mode 100644 index 0000000..959e2ef --- /dev/null +++ b/dashboard/src/components/SocialAnalyticsCard.jsx @@ -0,0 +1,104 @@ +import React, { useEffect, useState } from 'react'; +import { BarChart3, ExternalLink } from 'lucide-react'; +import { apiJson } from '../lib/api'; + +const fmtNum = (n) => new Intl.NumberFormat('en-US', { + notation: (n || 0) >= 10000 ? 'compact' : 'standard', + maximumFractionDigits: 1, +}).format(n || 0); + +// Upload-Post metric shapes vary per platform; read the first count that exists. +const postViews = (p) => { + const m = p.post_metrics || p.metrics || p; + return Number(m.views || m.impressions || m.plays || 0) || 0; +}; +const postTitle = (p) => p.title || p.caption || p.youtube_title || p.tiktok_title || 'untitled post'; +const postUrl = (p) => p.post_url || p.url || p.share_url || null; + +// Post-publication analytics: what the clips actually did out there. +// Paid-only by nature (social posting itself is paid in cloud): a 402 or any +// other failure simply hides the card — the account page works without it. +export default function SocialAnalyticsCard() { + const [data, setData] = useState(null); + + useEffect(() => { + let alive = true; + (async () => { + try { + const [imp, postsResp] = await Promise.all([ + apiJson('/api/social/analytics/impressions?period=last_month&breakdown=true'), + apiJson('/api/social/analytics/posts?limit=50'), + ]); + if (!alive) return; + const posts = (postsResp.posts || postsResp.data || postsResp.items || []) + .slice() + .sort((a, b) => postViews(b) - postViews(a)); + setData({ imp, posts }); + } catch (_) { /* free plan, nothing connected, or vendor hiccup — stay hidden */ } + })(); + return () => { alive = false; }; + }, []); + + if (!data) return null; + + const total = data.imp?.total_impressions + || data.posts.reduce((s, p) => s + postViews(p), 0); + const perPlatform = Object.entries(data.imp?.per_platform || {}) + .filter(([, v]) => Number(v) > 0) + .sort((a, b) => Number(b[1]) - Number(a[1])); + const top = data.posts.slice(0, 3); + + return ( +
+
+

+ Your posts +

+ last 30 days +
+ + {data.posts.length === 0 && !total ? ( +

+ Nothing published yet. Post a clip from your results and its views show up here. +

+ ) : ( + <> +
+ {fmtNum(total)} + impressions +
+ + {perPlatform.length > 0 && ( +
+ {perPlatform.map(([platform, v]) => ( + + {platform} {fmtNum(Number(v))} + + ))} +
+ )} + + {top.length > 0 && ( +
+ {top.map((p, i) => ( +
+ + {postTitle(p)} + {postUrl(p) && ( + + + + )} + + {fmtNum(postViews(p))} views +
+ ))} +
+ )} + + )} +
+ ); +}