import { useChannels } from "../hooks/useChannels"; import { usePlan } from "../hooks/usePlan"; import { useWorkspace } from "../hooks/useWorkspace"; import { useQuery } from "@tanstack/react-query"; import { wpApi } from "../api/wp-api"; import { viralySsoUrl } from "../utils/sso"; import clsx from "clsx"; const PLATFORM_ICONS: Record = { Facebook: "๐Ÿ“˜", Instagram: "๐Ÿ“ท", TikTok: "๐ŸŽต", Twitter: "๐•", LinkedIn: "๐Ÿ’ผ", Pinterest: "๐Ÿ“Œ", YouTube: "โ–ถ๏ธ", Threads: "๐Ÿงต", Bluesky: "๐Ÿฆ‹", Mastodon: "๐Ÿ˜", }; interface Props { onNavigate: (tab: string) => void; } export default function Dashboard({ onNavigate }: Props) { const { channels } = useChannels(); const { plan } = usePlan(); const { workspaceName } = useWorkspace(); const activeChannels = channels.filter((ch) => ch.status === "Active"); const { data: activity } = useQuery({ queryKey: ["activity", 1], queryFn: () => wpApi.get("activity?page=1"), staleTime: 60_000, }); const recentActivity = activity?.items?.slice(0, 5) || []; const totalShared = activity?.total || 0; return (
{/* What do you want to do? */}

What do you want to do?

{workspaceName && (

Workspace: {workspaceName}

)}
{plan && ( {plan.plan === "Free" && } {plan.plan === "Free" ? "Upgrade" : `${plan.plan} Plan`} )}
{[ { icon: "fa-solid fa-rotate", title: "Blog to Social", desc: "Share blog posts automatically", tab: "autopost" }, { icon: "fa-solid fa-pen-to-square", title: "Scheduler", desc: "Compose, schedule & manage posts", tab: "scheduler" }, { icon: "fa-solid fa-chart-line", title: "Analytics", desc: "View performance", tab: "analytics" }, ].map((a) => ( ))}
{/* Overview stats + profiles */}
{/* Stats */}

Overview

{activeChannels.length}

Profiles

{totalShared}

Shared

{plan?.plan || "โ€”"}

Plan

{/* Connected Profiles */}

Connected Profiles

{activeChannels.length > 0 ? (
{activeChannels.slice(0, 6).map((ch) => (
{ch.pictureUrl ? ( ) : ( {PLATFORM_ICONS[ch.type] || "๐ŸŒ"} )}
))} {activeChannels.length > 6 && ( +{activeChannels.length - 6} )}
{activeChannels.length} connected
) : ( )}
{/* Plan overview โ€” only for Free/Influencer */} {plan && (plan.plan === "Free" || plan.plan === "Influencer") && (

Your Plan

{plan.plan}
{/* What you have */} {plan.plan === "Free" ? ( <>
Up to 3 social profiles
10 posts per month
10 platforms supported
2 weeks analytics history
{/* What you'd unlock */}
Unlimited posts
AI caption generator
Content recycling
6+ months analytics
) : ( <>
Up to 5 social profiles
200 posts per month
AI captions & hashtags
6 months analytics
{/* What you'd unlock */}
Up to 15 profiles
12 months analytics
Team collaboration
Priority support
)}
{plan.plan === "Free" ? "Unlock more with Influencer" : "Unlock more with Business"} Upgrade
)} {/* Recent Activity */} {recentActivity.length > 0 && (

Recent Activity

{recentActivity.map((item: any) => (
{item.errorCount === 0 ? `โœ“ ${item.successCount}` : `โœ• ${item.errorCount}`} {item.title}
{item.channels?.slice(0, 4).map((ch: any, i: number) => ( {PLATFORM_ICONS[ch.type] || "๐ŸŒ"} ))}
{item.date}
))}
)}
); }