/** * Site Content Editor * Phase 6: Site Integration & Multi-Destination Publishing * Core CMS features: View all pages/posts, edit page content */ import React, { useState, useEffect } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { EditIcon, EyeIcon, FileTextIcon } 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 PageBlueprint { id: number; slug: string; title: string; type: string; status: string; order: number; blocks_json: any[]; site_blueprint: number; } interface SiteBlueprint { id: number; name: string; status: string; } export default function SiteContentEditor() { const { id: siteId } = useParams<{ id: string }>(); const navigate = useNavigate(); const toast = useToast(); const [blueprints, setBlueprints] = useState([]); const [selectedBlueprint, setSelectedBlueprint] = useState(null); const [pages, setPages] = useState([]); const [loading, setLoading] = useState(true); const [selectedPage, setSelectedPage] = useState(null); useEffect(() => { if (siteId) { loadBlueprints(); } }, [siteId]); useEffect(() => { if (selectedBlueprint) { loadPages(selectedBlueprint); } }, [selectedBlueprint]); const loadBlueprints = async () => { try { setLoading(true); const data = await fetchAPI(`/v1/site-builder/blueprints/?site=${siteId}`); const blueprintsList = Array.isArray(data?.results) ? data.results : Array.isArray(data) ? data : []; setBlueprints(blueprintsList); if (blueprintsList.length > 0) { setSelectedBlueprint(blueprintsList[0].id); } } catch (error: any) { toast.error(`Failed to load blueprints: ${error.message}`); } finally { setLoading(false); } }; const loadPages = async (blueprintId: number) => { try { const data = await fetchAPI(`/v1/site-builder/pages/?site_blueprint=${blueprintId}`); const pagesList = Array.isArray(data?.results) ? data.results : Array.isArray(data) ? data : []; setPages(pagesList.sort((a, b) => a.order - b.order)); } catch (error: any) { toast.error(`Failed to load pages: ${error.message}`); } }; const handleEditPage = (page: PageBlueprint) => { navigate(`/sites/${siteId}/pages/${page.id}/edit`); }; const handleViewPage = (page: PageBlueprint) => { navigate(`/sites/${siteId}/pages/${page.id}`); }; if (loading) { return (
Loading pages...
); } return (

Site Content Editor

View and edit content for site pages

{blueprints.length === 0 ? (

No site blueprints found for this site

) : (
{blueprints.length > 1 && ( )} {pages.length === 0 ? (

No pages found in this blueprint

) : (

Pages ({pages.length})

{pages.map((page) => (

{page.title}

/{page.slug} • {page.type} • {page.status}

{page.blocks_json && page.blocks_json.length > 0 && (

{page.blocks_json.length} block{page.blocks_json.length !== 1 ? 's' : ''}

)}
))}
)}
)}
); }