fix: guard vendor detail loading on instead of isPending to avoid stuck skeleton

This commit is contained in:
Matthias Hochmeister
2026-03-27 17:43:31 +01:00
parent b36e05d192
commit 1a66a66aab

View File

@@ -58,7 +58,7 @@ export default function LieferantDetail() {
}, [isNew]); }, [isNew]);
// ── Query ── // ── Query ──
const { data: vendor, isPending, isLoading, isError } = useQuery({ const { data: vendor, isError } = useQuery({
queryKey: ['lieferant', vendorId], queryKey: ['lieferant', vendorId],
queryFn: () => bestellungApi.getVendor(vendorId), queryFn: () => bestellungApi.getVendor(vendorId),
enabled: !isNew && !!vendorId, enabled: !isNew && !!vendorId,
@@ -138,7 +138,17 @@ export default function LieferantDetail() {
} }
// ── Loading / Error ── // ── Loading / Error ──
if (!isNew && isPending) { if (!isNew && !vendor) {
if (isError) {
return (
<DashboardLayout>
<Box sx={{ p: 4, textAlign: 'center' }}>
<Typography color="error">Lieferant nicht gefunden.</Typography>
<Button sx={{ mt: 2 }} onClick={() => navigate('/bestellungen?tab=1')}>Zurück</Button>
</Box>
</DashboardLayout>
);
}
return ( return (
<DashboardLayout> <DashboardLayout>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2, mb: 3 }}> <Box sx={{ display: 'flex', alignItems: 'center', gap: 2, mb: 3 }}>
@@ -154,17 +164,6 @@ export default function LieferantDetail() {
); );
} }
if (!isNew && !isPending && (isError || !vendor)) {
return (
<DashboardLayout>
<Box sx={{ p: 4, textAlign: 'center' }}>
<Typography color="error">Lieferant nicht gefunden.</Typography>
<Button sx={{ mt: 2 }} onClick={() => navigate('/bestellungen?tab=1')}>Zurück</Button>
</Box>
</DashboardLayout>
);
}
const isSaving = createVendor.isPending || updateVendor.isPending; const isSaving = createVendor.isPending || updateVendor.isPending;
return ( return (