diff --git a/src/App.tsx b/src/App.tsx index 2fea46a..d5e2cda 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -10,6 +10,7 @@ interface DayRecord { breakMins: number; workedHrs: number; overtimeMinutes: number; + notWorking?: boolean; } type Records = Partial>; @@ -17,7 +18,7 @@ type Records = Partial>; const STORAGE_KEY = 'workTrackerRecords'; const CARRYOVER_KEY = 'workTrackerCarryover'; -const DEFAULT_RECORD: DayRecord = { start: '', end: '', breakMins: 0, workedHrs: 0, overtimeMinutes: 0 }; +const DEFAULT_RECORD: DayRecord = { start: '', end: '', breakMins: 0, workedHrs: 0, overtimeMinutes: 0, notWorking: false }; const WEEKDAYS: Workday[] = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag']; @@ -81,11 +82,16 @@ function App() { } const getWeeklyBalance = () => { - const days: Workday[] = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag']; - return days.reduce((sum, day) => sum + (records[day]?.overtimeMinutes ?? 0), 0) + carryoverMinutes; + const days: Workday[] = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag']; + return days.reduce((sum, day) => { + const r = records[day]; + if (!r || r.notWorking) return sum; + return sum + (r.overtimeMinutes ?? 0); + }, 0) + carryoverMinutes; } const getWorkEndTime = () => { + if (record.notWorking) return '-'; const start = toMinutes(record.start); if (start === null) return '-'; const balance = selectedDay === 'Freitag' ? getWeeklyBalance() : 0; @@ -93,16 +99,25 @@ function App() { } const handleSave = () => { + if (record.notWorking) { + updateRecord({ workedHrs: 0, overtimeMinutes: 0 }); + return; + } const hours = getHourDiff(); updateRecord({ workedHrs: hours, overtimeMinutes: Math.round((hours - 8) * 60) }); } const handleResetWorkdays = () => { - const totalOvertime = WEEKDAYS.reduce((sum, day) => sum + (records[day]?.overtimeMinutes ?? 0), 0) + carryoverMinutes; + const totalOvertime = WEEKDAYS.reduce((sum, day) => { + const r = records[day]; + if (!r || r.notWorking) return sum; + return sum + (r.overtimeMinutes ?? 0); + }, 0) + carryoverMinutes; setCarryoverMinutes(totalOvertime); setRecords({}); } + const handleResetOvertime = () => { setCarryoverMinutes(0); } @@ -111,16 +126,42 @@ function App() {
({ + value: day, + label: ( + + {day} + + ), + }))} + value={selectedDay} onChange={(value) => setSelectedDay(value as Workday)} className={"mt-2"} /> + updateRecord({ start: value })} format="24h" clearable + disabled={record.notWorking} /> updateRecord({ end: value })} format="24h" clearable + disabled={record.notWorking} /> { if (event.key === 'Enter') handleSave(); }} + disabled={record.notWorking} /> - - Gearbeitete Stunden heute: {record.workedHrs.toFixed(2)} + {record.notWorking ? ( + Heute nicht gearbeitet + ) : ( + Gearbeitete Stunden heute: {record.workedHrs.toFixed(2)} + )} {carryoverMinutes !== 0 && ( Übernommene Überstunden aus Vorwoche: {carryoverMinutes} Minuten )} {selectedDay === 'Freitag' && ( Übertragen aus Montag bis Donnerstag (inkl. Vorwoche): {getWeeklyBalance()} Minuten )} - Wann du gehen kannst für 8 Stunden: {getWorkEndTime()} - {record.start && record.end && record.overtimeMinutes === 0 && ( + {!record.notWorking && ( + Wann du gehen kannst für 8 Stunden: {getWorkEndTime()} + )} + {!record.notWorking && record.start && record.end && record.overtimeMinutes === 0 && ( Du hast genau 8 Stunden gearbeitet. )} - {record.start && record.end && record.overtimeMinutes > 0 && ( + {!record.notWorking && record.start && record.end && record.overtimeMinutes > 0 && ( Überstunden: {record.overtimeMinutes} Minuten )} - {record.start && record.end && record.overtimeMinutes < 0 && ( + {!record.notWorking && record.start && record.end && record.overtimeMinutes < 0 && ( Fehlende Minuten für 8 Stunden: {-record.overtimeMinutes} Minuten )}