fix: show Close week button without requiring all workdays closed

The frontend was blocking week close until every workday had a
closed_days record, which no longer matches the backend's rules
(untracked days are implicitly 0h). Replace the all-workdays-closed
guard with a simple check: week has started (Monday ≤ today) and
is not already closed. The server returns a clear error if a day
with entries still needs closing.

Also fixes a pre-existing TS type narrowing error on currentSettings
and removes the now-unused .hint CSS rule.
This commit is contained in:
2026-04-30 18:08:06 +02:00
parent c675a7b01d
commit 563784d5fb

View File

@@ -9,7 +9,7 @@
let dayKeys = $derived(weekDayKeys(weekKey));
let closedDaysMap: Record<string, ClosedDay> = $state({});
let closedWeek: ClosedWeek | null = $state(null);
let currentSettings: Settings | null = $state(null);
let currentSettings = $state<Settings | null>(null);
let error = $state('');
async function load() {
@@ -61,10 +61,10 @@
currentSettings ? currentSettings.hours_per_week * 3_600_000 : 0
);
const allWorkdaysClosed = $derived(
currentSettings
? dayKeys.every((dk) => !isWorkday(dk, currentSettings!.workdays_mask) || !!closedDaysMap[dk])
: false
// Week can be closed if it's not already closed and the week has started
// (i.e. Monday ≤ today). The server enforces the detailed per-day rules.
const canCloseWeek = $derived(
!closedWeek && dayKeys[0] <= todayKey()
);
function prevWeek() { weekKey = offsetWeek(weekKey, -1); }
@@ -132,10 +132,8 @@
<p>Week closed — overtime: <strong>{formatDelta(closedWeek.delta_ms)}</strong></p>
<button onclick={handleReopenWeek}>Reopen week</button>
</div>
{:else if allWorkdaysClosed}
{:else if canCloseWeek}
<button class="btn close-week" onclick={handleCloseWeek}>Close week</button>
{:else}
<p class="hint">Close all workdays to close the week.</p>
{/if}
</div>
@@ -167,5 +165,4 @@
.btn.close-week { background: #343a40; color: #fff; border: none; padding: 0.55rem 1.4rem; border-radius: 6px; font-size: 1rem; font-weight: 600; }
.week-closed { background: #d4edda; border-radius: 8px; padding: 0.75rem 1rem; display: flex; align-items: center; justify-content: space-between; }
.week-closed button { background: none; border: 1px solid #155724; color: #155724; border-radius: 6px; padding: 0.3rem 0.6rem; font-size: 0.875rem; }
.hint { color: #6c757d; font-size: 0.875rem; font-style: italic; }
</style>