import React, { useState, useEffect } from 'react'; import './Dashboard.css'; export default function Dashboard() { const [ dashboardData, setDashboardData ] = useState( { postsCount: 0, pagesCount: 0, commentsCount: 0, usersCount: 0, recentPosts: [], recentComments: [], loading: true, } ); useEffect( () => { // Fetch dashboard data from WordPress REST API const fetchDashboardData = async () => { try { const [ posts, pages, comments, users ] = await Promise.all( [ fetch( `${ window.helixData?.restUrl || '/wp-json/wp/v2/' }posts?per_page=5` ), fetch( `${ window.helixData?.restUrl || '/wp-json/wp/v2/' }pages?per_page=5` ), fetch( `${ window.helixData?.restUrl || '/wp-json/wp/v2/' }comments?per_page=5` ), fetch( `${ window.helixData?.restUrl || '/wp-json/wp/v2/' }users?per_page=5` ), ] ); const [ postsData, pagesData, commentsData, usersData ] = await Promise.all( [ posts.json(), pages.json(), comments.json(), users.json(), ] ); setDashboardData( { postsCount: posts.headers.get( 'X-WP-Total' ) || postsData.length, pagesCount: pages.headers.get( 'X-WP-Total' ) || pagesData.length, commentsCount: comments.headers.get( 'X-WP-Total' ) || commentsData.length, usersCount: users.headers.get( 'X-WP-Total' ) || usersData.length, recentPosts: postsData.slice( 0, 5 ), recentComments: commentsData.slice( 0, 5 ), loading: false, } ); } catch ( error ) { // Error fetching dashboard data setDashboardData( ( prev ) => ( { ...prev, loading: false } ) ); } }; fetchDashboardData(); }, [] ); const StatsCard = ( { title, count, icon, color } ) => (
{ icon }

{ count }

{ title }

); const formatDate = ( dateString ) => { return new Date( dateString ).toLocaleDateString( 'en-US', { year: 'numeric', month: 'short', day: 'numeric', } ); }; if ( dashboardData.loading ) { return (

Dashboard

Loading dashboard...

); } return (

Welcome to Helix

Your modern WordPress admin experience

{ /* Statistics Overview */ }
{ /* Main Content Area */ }
{ /* Recent Posts Widget */ }

Recent Posts

View All
{ dashboardData.recentPosts.length > 0 ? ( ) : (

No posts yet.{ ' ' } Create your first post!

) }
{ /* Recent Comments Widget */ }

Recent Comments

View All
{ dashboardData.recentComments.length > 0 ? (
    { dashboardData.recentComments.map( ( comment ) => (
  • { comment.author_name }

    { comment.content.rendered .replace( /<[^>]*>/g, '' ) .substring( 0, 100 ) } ...

    { formatDate( comment.date ) }

    { comment.status }
  • ) ) }
) : (

No comments yet.

) }
{ /* Quick Actions Widget */ }

Quick Actions

✏️ Write a Post 📄 Create a Page 📁 Upload Media 💬 Moderate Comments
{ /* WordPress News Widget */ }

WordPress News

Stay updated with the latest WordPress news and updates.

WordPress 6.4 “Shirley” Released

The latest version includes new features and improvements...

Read more
); }