/** * Site Dashboard (Advanced) * Phase 7: UI Components & Prompt Management * Site overview with statistics and analytics */ import React, { useState, useEffect } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { EyeIcon, FileTextIcon, PlugIcon, TrendingUpIcon, CalendarIcon, GlobeIcon } from 'lucide-react'; import PageMeta from '../../components/common/PageMeta'; import { Card } from '../../components/ui/card'; import Button from '../../components/ui/button/Button'; import { useToast } from '../../components/ui/toast/ToastContainer'; import { fetchAPI } from '../../services/api'; interface Site { id: number; name: string; slug: string; site_type: string; hosting_type: string; status: string; is_active: boolean; created_at: string; updated_at: string; domain?: string; } interface SiteStats { total_pages: number; published_pages: number; draft_pages: number; total_content: number; published_content: number; integrations_count: number; deployments_count: number; last_deployment?: string; views_count?: number; visitors_count?: number; } export default function SiteDashboard() { const { id: siteId } = useParams<{ id: string }>(); const navigate = useNavigate(); const toast = useToast(); const [site, setSite] = useState(null); const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { if (siteId) { loadSiteData(); } }, [siteId]); const loadSiteData = async () => { try { setLoading(true); const [siteData, statsData] = await Promise.all([ fetchAPI(`/v1/auth/sites/${siteId}/`), fetchSiteStats(), ]); if (siteData) { setSite(siteData); } if (statsData) { setStats(statsData); } } catch (error: any) { toast.error(`Failed to load site data: ${error.message}`); } finally { setLoading(false); } }; const fetchSiteStats = async (): Promise => { try { // TODO: Create backend endpoint for site stats // For now, return mock data structure return { total_pages: 0, published_pages: 0, draft_pages: 0, total_content: 0, published_content: 0, integrations_count: 0, deployments_count: 0, }; } catch (error) { console.error('Error fetching site stats:', error); return null; } }; if (loading) { return (
Loading site dashboard...
); } if (!site) { return (

Site not found

); } const statCards = [ { label: 'Total Pages', value: stats?.total_pages || 0, icon: , color: 'blue', link: `/sites/${siteId}/pages`, }, { label: 'Published Pages', value: stats?.published_pages || 0, icon: , color: 'green', link: `/sites/${siteId}/pages?status=published`, }, { label: 'Draft Pages', value: stats?.draft_pages || 0, icon: , color: 'amber', link: `/sites/${siteId}/pages?status=draft`, }, { label: 'Integrations', value: stats?.integrations_count || 0, icon: , color: 'purple', link: `/sites/${siteId}/settings?tab=integrations`, }, { label: 'Deployments', value: stats?.deployments_count || 0, icon: , color: 'teal', link: `/sites/${siteId}/preview`, }, { label: 'Total Content', value: stats?.total_content || 0, icon: , color: 'indigo', link: `/sites/${siteId}/content`, }, ]; return (
{/* Header */}

{site.name}

{site.slug} • {site.site_type} • {site.hosting_type}

{site.domain && (

{site.domain}

)}
{/* Stats Grid */}
{statCards.map((stat, index) => ( stat.link && navigate(stat.link)} >

{stat.label}

{stat.value}

{stat.icon}
))}
{/* Quick Actions */}

Quick Actions

{/* Recent Activity */}

Recent Activity

{stats?.last_deployment ? (

Last Deployment

{new Date(stats.last_deployment).toLocaleString()}

) : (

No recent activity

)}
); }