diff --git a/client/src/pages/LitterList.jsx b/client/src/pages/LitterList.jsx index a3720d4..fc056f1 100644 --- a/client/src/pages/LitterList.jsx +++ b/client/src/pages/LitterList.jsx @@ -1,10 +1,16 @@ import { useEffect, useState } from 'react' -import { Activity } from 'lucide-react' +import { Activity, Plus, Edit2, Trash2, ChevronRight } from 'lucide-react' +import { useNavigate } from 'react-router-dom' import axios from 'axios' +import LitterForm from '../components/LitterForm' function LitterList() { const [litters, setLitters] = useState([]) const [loading, setLoading] = useState(true) + const [showForm, setShowForm] = useState(false) + const [editingLitter, setEditingLitter] = useState(null) + const [prefill, setPrefill] = useState(null) + const navigate = useNavigate() useEffect(() => { fetchLitters() @@ -14,49 +20,128 @@ function LitterList() { try { const res = await axios.get('/api/litters') setLitters(res.data) - setLoading(false) } catch (error) { console.error('Error fetching litters:', error) + } finally { setLoading(false) } } + const handleCreate = () => { + setEditingLitter(null) + setPrefill(null) + setShowForm(true) + } + + const handleEdit = (e, litter) => { + e.stopPropagation() + setEditingLitter(litter) + setPrefill(null) + setShowForm(true) + } + + const handleDelete = async (e, id) => { + e.stopPropagation() + if (!window.confirm('Delete this litter record? Puppies will be unlinked but not deleted.')) return + try { + await axios.delete(`/api/litters/${id}`) + fetchLitters() + } catch (error) { + console.error('Error deleting litter:', error) + } + } + + const handleSave = () => { + fetchLitters() + } + if (loading) { return
Start tracking breeding records
+Create a litter after a breeding cycle to track puppies
+- Breeding Date: {new Date(litter.breeding_date).toLocaleDateString()} -
- {litter.whelping_date && ( -- Whelping Date: {new Date(litter.whelping_date).toLocaleDateString()} -
- )} -- Puppies: {litter.puppy_count || litter.puppies?.length || 0} -
++ {litter.notes} +
+ )} +