From 4af656667d8830e2f27f404e5602a0cf31923a9a Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 9 Mar 2026 00:08:18 -0500 Subject: [PATCH] Add LitterForm component for litter management --- client/src/components/LitterForm.jsx | 178 +++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 client/src/components/LitterForm.jsx diff --git a/client/src/components/LitterForm.jsx b/client/src/components/LitterForm.jsx new file mode 100644 index 0000000..a86430a --- /dev/null +++ b/client/src/components/LitterForm.jsx @@ -0,0 +1,178 @@ +import { useState, useEffect } from 'react' +import { X } from 'lucide-react' +import axios from 'axios' + +function LitterForm({ litter, onClose, onSave }) { + const [formData, setFormData] = useState({ + sire_id: '', + dam_id: '', + breeding_date: '', + whelping_date: '', + puppy_count: 0, + notes: '' + }) + const [dogs, setDogs] = useState([]) + const [loading, setLoading] = useState(false) + const [error, setError] = useState('') + + useEffect(() => { + fetchDogs() + if (litter) { + setFormData({ + sire_id: litter.sire_id || '', + dam_id: litter.dam_id || '', + breeding_date: litter.breeding_date || '', + whelping_date: litter.whelping_date || '', + puppy_count: litter.puppy_count || 0, + notes: litter.notes || '' + }) + } + }, [litter]) + + const fetchDogs = async () => { + try { + const res = await axios.get('/api/dogs') + setDogs(res.data) + } catch (error) { + console.error('Error fetching dogs:', error) + } + } + + const handleChange = (e) => { + const { name, value } = e.target + setFormData(prev => ({ ...prev, [name]: value })) + } + + const handleSubmit = async (e) => { + e.preventDefault() + setError('') + setLoading(true) + + try { + if (litter) { + await axios.put(`/api/litters/${litter.id}`, formData) + } else { + await axios.post('/api/litters', formData) + } + onSave() + onClose() + } catch (error) { + setError(error.response?.data?.error || 'Failed to save litter') + setLoading(false) + } + } + + const males = dogs.filter(d => d.sex === 'male') + const females = dogs.filter(d => d.sex === 'female') + + return ( +
+
e.stopPropagation()}> +
+

{litter ? 'Edit Litter' : 'Create New Litter'}

+ +
+ +
+ {error &&
{error}
} + +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ +
+ +