feat: always show checklists in overview and add quarterly/halfyearly intervals

This commit is contained in:
Matthias Hochmeister
2026-03-28 17:46:31 +01:00
parent a52bb2a57c
commit 6091d6c4dd
3 changed files with 69 additions and 44 deletions

View File

@@ -83,6 +83,8 @@ const formatDate = (iso?: string) =>
const INTERVALL_LABELS: Record<string, string> = {
weekly: 'Wöchentlich',
monthly: 'Monatlich',
quarterly: 'Quartalsweise',
halfyearly: 'Halbjährlich',
yearly: 'Jährlich',
custom: 'Benutzerdefiniert',
};
@@ -105,16 +107,16 @@ function getAssignmentLabel(v: ChecklistVorlage): string {
return 'Global';
}
function getDueColor(nextDue?: string): 'error' | 'warning' | 'success' {
if (!nextDue) return 'success';
function getDueColor(nextDue?: string | null, intervall?: string | null): 'error' | 'warning' | 'success' | 'default' {
if (!nextDue) return intervall ? 'warning' : 'default'; // has recurrence but never run → warn; no recurrence → neutral
const daysUntil = Math.ceil((new Date(nextDue).getTime() - Date.now()) / 86400000);
if (daysUntil < 0) return 'error';
if (daysUntil <= 3) return 'warning';
return 'success';
}
function getDueLabel(nextDue?: string): string {
if (!nextDue) return 'Aktuell';
function getDueLabel(nextDue?: string | null, intervall?: string | null): string {
if (!nextDue) return intervall ? 'Noch nie ausgeführt' : 'Manuell';
const daysUntil = Math.ceil((new Date(nextDue).getTime() - Date.now()) / 86400000);
if (daysUntil < 0) return `${Math.abs(daysUntil)}d überfällig`;
if (daysUntil === 0) return 'Heute fällig';
@@ -257,12 +259,12 @@ function OverviewTab({ overview, loading, canExecute, navigate }: OverviewTabPro
const equipment = overview?.equipment ?? [];
if (vehicles.length === 0 && equipment.length === 0) {
return <Alert severity="success" sx={{ mt: 1 }}>Keine offenen oder fälligen Checks</Alert>;
return <Alert severity="info" sx={{ mt: 1 }}>Keine Checklisten zugewiesen</Alert>;
}
const renderChecklistRow = (cl: ChecklistOverviewChecklist, itemId: string, type: 'fahrzeug' | 'ausruestung') => {
const color = getDueColor(cl.next_due);
const label = getDueLabel(cl.next_due);
const color = getDueColor(cl.next_due, cl.intervall);
const label = getDueLabel(cl.next_due, cl.intervall);
const param = type === 'fahrzeug' ? `fahrzeug=${itemId}` : `ausruestung=${itemId}`;
return (
<ListItem
@@ -311,7 +313,8 @@ function OverviewTab({ overview, loading, canExecute, navigate }: OverviewTabPro
</Typography>
{items.map((item) => {
const totalDue = item.checklists.length;
const hasOverdue = item.checklists.some((cl) => getDueColor(cl.next_due) === 'error');
const hasOverdue = item.checklists.some((cl) => getDueColor(cl.next_due, cl.intervall) === 'error');
const badgeColor = hasOverdue ? 'error' : item.checklists.some((cl) => getDueColor(cl.next_due, cl.intervall) === 'warning') ? 'warning' : 'default';
return (
<Accordion key={item.id} variant="outlined" disableGutters>
<AccordionSummary expandIcon={<ExpandMore />}>
@@ -319,7 +322,7 @@ function OverviewTab({ overview, loading, canExecute, navigate }: OverviewTabPro
<Typography variant="subtitle1">{item.name}</Typography>
<Badge
badgeContent={totalDue}
color={hasOverdue ? 'error' : 'warning'}
color={badgeColor as any}
sx={{ ml: 'auto', mr: 2 }}
/>
</Box>
@@ -593,8 +596,10 @@ function VorlagenTab({ vorlagen, loading, fahrzeugTypen, queryClient, showSucces
<MenuItem value="">Kein Intervall</MenuItem>
<MenuItem value="weekly">Wöchentlich</MenuItem>
<MenuItem value="monthly">Monatlich</MenuItem>
<MenuItem value="quarterly">Quartalsweise (alle 3 Monate)</MenuItem>
<MenuItem value="halfyearly">Halbjährlich (alle 6 Monate)</MenuItem>
<MenuItem value="yearly">Jährlich</MenuItem>
<MenuItem value="custom">Benutzerdefiniert</MenuItem>
<MenuItem value="custom">Benutzerdefiniert (Tage)</MenuItem>
</Select>
</FormControl>
{form.intervall === 'custom' && (