Initial commit: Fahrrad Verschleißteile Tracker
- Next.js SPA mit Bun Runtime - Prisma mit SQLite Datenbank - Vollständige CRUD-Operationen für Fahrräder, Verschleißteile und Wartungshistorie - Warnsystem für bevorstehende Wartungen - Statistik-Features (Gesamtkosten, durchschnittliche Lebensdauer) - Zod-Validierung für alle API-Requests - Umfassende Test-Suite (41 Tests)
This commit is contained in:
50
app/bikes/[id]/page.tsx
Normal file
50
app/bikes/[id]/page.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useParams, useRouter } from 'next/navigation'
|
||||
import { WearPartWithHistory } from '@/types'
|
||||
import BikeDetail from '@/app/components/BikeDetail'
|
||||
|
||||
export default function BikeDetailPage() {
|
||||
const params = useParams()
|
||||
const router = useRouter()
|
||||
const [bike, setBike] = useState<any>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
if (params.id) {
|
||||
fetchBike(params.id as string)
|
||||
}
|
||||
}, [params.id])
|
||||
|
||||
const fetchBike = async (id: string) => {
|
||||
try {
|
||||
const response = await fetch(`/api/bikes/${id}`)
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
setBike(data)
|
||||
} else if (response.status === 404) {
|
||||
router.push('/')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching bike:', error)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center">
|
||||
<div className="text-lg">Lade...</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!bike) {
|
||||
return null
|
||||
}
|
||||
|
||||
return <BikeDetail bike={bike} onUpdate={fetchBike} />
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user