diff --git a/src/components/timesheet/TimeEntryModal.tsx b/src/components/timesheet/TimeEntryModal.tsx index a57e638..753a10d 100644 --- a/src/components/timesheet/TimeEntryModal.tsx +++ b/src/components/timesheet/TimeEntryModal.tsx @@ -33,14 +33,6 @@ export function TimeEntryModal({ isOpen, onClose, date, entry }: TimeEntryModalP const [taskId, setTaskId] = useState(''); const [hours, setHours] = useState(''); const [minutes, setMinutes] = useState(''); - - // When hours is 24, minutes must be 0 - const handleHoursChange = (value: string) => { - setHours(value); - if (parseInt(value) >= 24) { - setMinutes('0'); - } - }; const [notes, setNotes] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const [extensionInstalled, setExtensionInstalled] = useState(null); @@ -126,10 +118,11 @@ export function TimeEntryModal({ isOpen, onClose, date, entry }: TimeEntryModalP // Find task by code and use its id const task = project?.tasks.find((t) => t.code === entry.taskId); setTaskId(task?.id || ''); - const h = Math.floor(entry.hours); - const m = Math.round((entry.hours - h) * 60); - setHours(h.toString()); - setMinutes(m.toString()); + const totalMinutes = Math.round(entry.hours * 60); + const h = Math.floor(totalMinutes / 60); + const m = totalMinutes % 60; + setHours(h > 0 ? h.toString() : ''); + setMinutes(m > 0 ? m.toString() : ''); setNotes(entry.notes || ''); } else { // New entry - use matching customer option value @@ -183,7 +176,9 @@ export function TimeEntryModal({ isOpen, onClose, date, entry }: TimeEntryModalP e.preventDefault(); if (!date || !projectId || !taskId || isSubmitting) return; - const totalHours = (parseInt(hours) || 0) + (parseInt(minutes) || 0) / 60; + const h = Math.max(0, Math.min(24, parseInt(hours) || 0)); + const m = h >= 24 ? 0 : Math.max(0, Math.min(59, parseInt(minutes) || 0)); + const totalHours = h + m / 60; if (totalHours <= 0) return; const project = projects.find((p) => p.id === projectId); @@ -341,17 +336,33 @@ export function TimeEntryModal({ isOpen, onClose, date, entry }: TimeEntryModalP min="0" max="24" value={hours} - onChange={(e) => handleHoursChange(e.target.value)} + onChange={(e) => { + const v = e.target.value; + if (v === '') { + setHours(''); + return; + } + const n = Math.max(0, Math.min(24, parseInt(v) || 0)); + setHours(n.toString()); + if (n >= 24) setMinutes('0'); + }} placeholder="0" /> setMinutes(e.target.value)} + onChange={(e) => { + const v = e.target.value; + if (v === '') { + setMinutes(''); + return; + } + const n = Math.max(0, Math.min(59, parseInt(v) || 0)); + setMinutes(n.toString()); + }} placeholder="0" disabled={parseInt(hours) >= 24} />