import React, { useState, useEffect } from 'react'; import { Link } from 'react-router-dom'; import api from '../services/api'; import { PlusIcon, ArrowPathIcon } from '@heroicons/react/24/outline'; const Dashboard = () => { const [recentWorkflows, setRecentWorkflows] = useState([]); const [stats, setStats] = useState({ totalWorkflows: 0, executionsToday: 0, activeWebhooks: 0 }); const [loading, setLoading] = useState(true); useEffect(() => { const fetchDashboardData = async () => { try { // Fetch workflows const workflowsResponse = await api.get('/api/workflows'); const workflows = workflowsResponse.data.workflows || []; // Sort by updated_at and take the 5 most recent const sortedWorkflows = [...workflows].sort( (a, b) => new Date(b.updated_at) - new Date(a.updated_at) ).slice(0, 5); setRecentWorkflows(sortedWorkflows); // Set stats setStats({ totalWorkflows: workflows.length, executionsToday: 0, // This would come from a separate API endpoint activeWebhooks: workflows.reduce((count, workflow) => { // Count webhook nodes in each workflow const webhookNodes = workflow.nodes.filter(node => node.type === 'webhook'); return count + webhookNodes.length; }, 0) }); } catch (error) { console.error('Error fetching dashboard data:', error); } finally { setLoading(false); } }; fetchDashboardData(); }, []); return (
{/* Stats */}
Total Workflows
{loading ? (
) : ( stats.totalWorkflows )}
Executions Today
{loading ? (
) : ( stats.executionsToday )}
Active Webhooks
{loading ? (
) : ( stats.activeWebhooks )}
{/* Recent Workflows */}

Recent Workflows

New Workflow
{loading ? (
{[...Array(3)].map((_, i) => (
))}
) : recentWorkflows.length > 0 ? (
    {recentWorkflows.map((workflow) => (
  • {workflow.name}
    {new Date(workflow.updated_at).toLocaleDateString()}
    {workflow.nodes.length} nodes, {workflow.connections.length} connections
  • ))}
) : (

You don't have any workflows yet.

Create your first workflow
)}
{recentWorkflows.length > 0 && (
View all workflows
)}
); }; export default Dashboard;