import React, { useEffect, useState } from 'react'; import axios from 'axios'; const WorkSchedule = () => { const [schedule, setSchedule] = useState([]); const [error, setError] = useState(false); // State to track if there's an error useEffect(() => { const fetchSchedule = async () => { try { const response = await axios.get('http://localhost:5000/api/schedules'); setSchedule(response.data); setError(false); // Reset error state if the fetch succeeds } catch (error) { console.error('Error fetching the schedule data:', error); setError(true); // Set error to true if the fetch fails } }; fetchSchedule(); }, []); return (
| First Name | Last Name | Phone | Hours Today | Hours This Week | Hourly Rate | Estimated Weekly Earnings | |
|---|---|---|---|---|---|---|---|
| Failed to fetch data. | |||||||
| {person.first_name} | {person.last_name} | {person.email} | {person.phone} | {person.hours_worked_today} | {person.hours_worked_week} | ${person.hourly_rate.toFixed(2)} | ${person.estimated_weekly_earnings.toFixed(2)} |