rework vehicle handling
This commit is contained in:
@@ -111,12 +111,12 @@ const IncidentStatsChart: React.FC<IncidentStatsChartProps> = ({ stats, loading
|
||||
}
|
||||
|
||||
const monthlyData = buildMonthlyData(
|
||||
stats.monthly,
|
||||
stats.prev_year_monthly,
|
||||
stats.monthly ?? [],
|
||||
stats.prev_year_monthly ?? [],
|
||||
stats.jahr
|
||||
);
|
||||
|
||||
const pieData = stats.by_art.map((row) => ({
|
||||
const pieData = (stats.by_art ?? []).map((row) => ({
|
||||
name: EINSATZ_ART_LABELS[row.einsatz_art],
|
||||
value: row.anzahl,
|
||||
art: row.einsatz_art,
|
||||
|
||||
@@ -140,7 +140,7 @@ function Dashboard() {
|
||||
title="Fahrzeuge einsatzbereit"
|
||||
value={
|
||||
vehicleStats
|
||||
? `${vehicleStats.einsatzbereit}/${vehicleStats.total}`
|
||||
? `${vehicleStats?.einsatzbereit}/${vehicleStats?.total}`
|
||||
: '—'
|
||||
}
|
||||
icon={DirectionsCar}
|
||||
|
||||
@@ -35,9 +35,11 @@ import {
|
||||
Edit,
|
||||
Error as ErrorIcon,
|
||||
LocalFireDepartment,
|
||||
MoreHoriz,
|
||||
PauseCircle,
|
||||
ReportProblem,
|
||||
School,
|
||||
Verified,
|
||||
Warning,
|
||||
} from '@mui/icons-material';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
@@ -303,10 +305,9 @@ interface WartungTabProps {
|
||||
}
|
||||
|
||||
const WARTUNG_ART_ICONS: Record<string, React.ReactElement> = {
|
||||
Kraftstoff: <LocalFireDepartment color="action" />,
|
||||
Reparatur: <Build color="warning" />,
|
||||
Inspektion: <Assignment color="primary" />,
|
||||
Hauptuntersuchung: <CheckCircle color="success" />,
|
||||
'§57a Prüfung': <Verified color="success" />,
|
||||
'Service': <Build color="warning" />,
|
||||
'Sonstiges': <MoreHoriz color="action" />,
|
||||
default: <Build color="action" />,
|
||||
};
|
||||
|
||||
@@ -417,7 +418,7 @@ const WartungTab: React.FC<WartungTabProps> = ({ fahrzeugId, wartungslog, onAdde
|
||||
onChange={(e) => setForm((f) => ({ ...f, art: (e.target.value || undefined) as WartungslogArt | undefined }))}
|
||||
>
|
||||
<MenuItem value="">— Bitte wählen —</MenuItem>
|
||||
{(['Inspektion', 'Reparatur', 'Kraftstoff', 'Reifenwechsel', 'Hauptuntersuchung', 'Reinigung', 'Sonstiges'] as WartungslogArt[]).map((a) => (
|
||||
{(['§57a Prüfung', 'Service', 'Sonstiges'] as WartungslogArt[]).map((a) => (
|
||||
<MenuItem key={a} value={a}>{a}</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
|
||||
@@ -387,7 +387,7 @@ function MitgliedDetail() {
|
||||
</Typography>
|
||||
)}
|
||||
|
||||
{profile && profile.funktion.length > 0 && (
|
||||
{profile && Array.isArray(profile.funktion) && profile.funktion.length > 0 && (
|
||||
<Box sx={{ display: 'flex', gap: 0.5, mt: 1, flexWrap: 'wrap' }}>
|
||||
{profile.funktion.map((f) => (
|
||||
<Chip key={f} label={f} size="small" color="secondary" variant="outlined" />
|
||||
|
||||
@@ -354,7 +354,7 @@ function Mitglieder() {
|
||||
{/* Funktion(en) */}
|
||||
<TableCell>
|
||||
<Box sx={{ display: 'flex', gap: 0.5, flexWrap: 'wrap' }}>
|
||||
{member.funktion.length > 0
|
||||
{Array.isArray(member.funktion) && member.funktion.length > 0
|
||||
? member.funktion.map((f) => (
|
||||
<Chip key={f} label={f} size="small" variant="outlined" color="secondary" />
|
||||
))
|
||||
|
||||
@@ -216,6 +216,9 @@ export const incidentsApi = {
|
||||
const response = await api.get<{ success: boolean; data: IncidentListResponse }>(
|
||||
`/api/incidents?${params.toString()}`
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -227,6 +230,9 @@ export const incidentsApi = {
|
||||
const response = await api.get<{ success: boolean; data: EinsatzStats }>(
|
||||
`/api/incidents/stats${params}`
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -237,6 +243,9 @@ export const incidentsApi = {
|
||||
const response = await api.get<{ success: boolean; data: EinsatzDetail }>(
|
||||
`/api/incidents/${id}`
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -248,6 +257,9 @@ export const incidentsApi = {
|
||||
'/api/incidents',
|
||||
payload
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -259,6 +271,9 @@ export const incidentsApi = {
|
||||
`/api/incidents/${id}`,
|
||||
payload
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
|
||||
@@ -55,10 +55,13 @@ export const membersService = {
|
||||
const response = await api.get<ApiListResponse<MemberListItem>>(
|
||||
`/api/members?${params.toString()}`
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return {
|
||||
items: response.data.data,
|
||||
total: response.data.meta.total,
|
||||
page: response.data.meta.page,
|
||||
total: response.data.meta?.total ?? 0,
|
||||
page: response.data.meta?.page ?? 1,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -69,6 +72,9 @@ export const membersService = {
|
||||
const response = await api.get<ApiItemResponse<MemberWithProfile>>(
|
||||
`/api/members/${userId}`
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -84,6 +90,9 @@ export const membersService = {
|
||||
`/api/members/${userId}/profile`,
|
||||
data
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -100,6 +109,9 @@ export const membersService = {
|
||||
`/api/members/${userId}`,
|
||||
data
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -108,6 +120,9 @@ export const membersService = {
|
||||
*/
|
||||
async getMemberStats(): Promise<MemberStats> {
|
||||
const response = await api.get<ApiItemResponse<MemberStats>>('/api/members/stats');
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -15,6 +15,9 @@ async function unwrap<T>(
|
||||
promise: ReturnType<typeof api.get<{ success: boolean; data: T }>>
|
||||
): Promise<T> {
|
||||
const response = await promise;
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
@@ -44,6 +47,9 @@ export const vehiclesApi = {
|
||||
'/api/vehicles',
|
||||
payload
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -52,6 +58,9 @@ export const vehiclesApi = {
|
||||
`/api/vehicles/${id}`,
|
||||
payload
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
@@ -74,6 +83,9 @@ export const vehiclesApi = {
|
||||
`/api/vehicles/${id}/wartung`,
|
||||
payload
|
||||
);
|
||||
if (!response.data?.data) {
|
||||
throw new Error('Invalid API response');
|
||||
}
|
||||
return response.data.data;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -17,12 +17,8 @@ export const FahrzeugStatusLabel: Record<FahrzeugStatus, string> = {
|
||||
};
|
||||
|
||||
export type WartungslogArt =
|
||||
| 'Inspektion'
|
||||
| 'Reparatur'
|
||||
| 'Kraftstoff'
|
||||
| 'Reifenwechsel'
|
||||
| 'Hauptuntersuchung'
|
||||
| 'Reinigung'
|
||||
| '§57a Prüfung'
|
||||
| 'Service'
|
||||
| 'Sonstiges';
|
||||
|
||||
// ── API Response Shapes ───────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user