import React, { useState, useEffect } from 'react'; import axios from 'axios'; const API_URL = process.env.REACT_APP_API_URL || 'http://localhost:4000'; function App() { const [users, setUsers] = useState([]); const [stats, setStats] = useState({ totalUsers: 0, activeUsers: 0, serverStatus: 'Unknown' }); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { fetchData(); }, []); const fetchData = async () => { try { setLoading(true); setError(null); // Fetch users and stats in parallel const [usersResponse, statsResponse] = await Promise.all([ axios.get(`${API_URL}/api/users`), axios.get(`${API_URL}/api/stats`) ]); setUsers(usersResponse.data); setStats(statsResponse.data); } catch (err) { console.error('Error fetching data:', err); setError(`Failed to fetch data: ${err.message}`); } finally { setLoading(false); } }; const addSampleUser = async () => { try { const sampleUsers = [ { name: 'Alice Johnson', email: 'alice@example.com', role: 'Developer' }, { name: 'Bob Smith', email: 'bob@example.com', role: 'Designer' }, { name: 'Charlie Brown', email: 'charlie@example.com', role: 'Manager' }, { name: 'Diana Prince', email: 'diana@example.com', role: 'Tester' } ]; const randomUser = sampleUsers[Math.floor(Math.random() * sampleUsers.length)]; await axios.post(`${API_URL}/api/users`, randomUser); // Refresh data fetchData(); } catch (err) { console.error('Error adding user:', err); setError(`Failed to add user: ${err.message}`); } }; if (loading) { return (
Multi-Component Application Testing Platform
Frontend: React 18 (Port 3000)
Backend API: Node.js + Express (Port 5000)
Database: PostgreSQL (Port 5432)
Environment: {process.env.NODE_ENV || 'development'}
API URL: {API_URL}
Total Users
Active Users
Server Status
No users found. Click "Add Sample User" to get started!
Email: {user.email}
Role: {user.role}
Created: {new Date(user.created_at).toLocaleDateString()}
This application demonstrates: