import React from 'react'; import { useQuery } from '@tanstack/react-query'; import { type TimeEntry, type TimeSpentSummary } from '@emberclone/shared'; interface TimeSpentSummaryProps { dailyTargetHours?: number; } const TimeSpentSummary: React.FC = ({ dailyTargetHours = 8 }) => { const { data, isLoading, error } = useQuery({ queryKey: ['time-spent-summary'], queryFn: async () => { const res = await fetch('/api/time/summary'); if (!res.ok) throw new Error('Failed to fetch summary'); return res.json(); }, }); if (isLoading) return
Loading summary...
; if (error) return
Error loading summary
; const periods = [ { label: 'Today', value: data?.today || 0, key: 'today' }, { label: 'This Week', value: data?.week || 0, key: 'week' }, { label: 'This Month', value: data?.month || 0, key: 'month' }, ]; const formatHours = (decimalHours: number) => { const h = Math.floor(decimalHours); const m = Math.round((decimalHours - h) * 60); return `${h}h ${m}m`; }; return (

Time Spent

{periods.map((period) => { // For "Today", we compare against dailyTarget. For others, we just show the value. const isToday = period.key === 'today'; const percentage = isToday ? Math.min((period.value / dailyTargetHours) * 100, 100) : 0; return (
{period.label} {formatHours(period.value)}
{isToday && (
)}
); })}
); }; export default TimeSpentSummary;