diff --git a/client/src/pages/LitterDetail.jsx b/client/src/pages/LitterDetail.jsx index ee58a88..0023c01 100644 --- a/client/src/pages/LitterDetail.jsx +++ b/client/src/pages/LitterDetail.jsx @@ -1,9 +1,254 @@ import { useEffect, useState } from 'react' import { useParams, useNavigate } from 'react-router-dom' -import { ArrowLeft, Plus, X, ExternalLink, Dog } from 'lucide-react' +import { ArrowLeft, Plus, X, ExternalLink, Dog, Weight, ChevronDown, ChevronUp, Trash2 } from 'lucide-react' import axios from 'axios' import LitterForm from '../components/LitterForm' +// ─── Puppy Log Panel ──────────────────────────────────────────────────────────── +function PuppyLogPanel({ litterId, puppy, whelpingDate }) { + const [open, setOpen] = useState(false) + const [logs, setLogs] = useState([]) + const [loading, setLoading] = useState(false) + const [showAdd, setShowAdd] = useState(false) + const [form, setForm] = useState({ + record_date: whelpingDate || '', + weight_oz: '', + weight_lbs: '', + notes: '', + record_type: 'weight_log' + }) + const [saving, setSaving] = useState(false) + + useEffect(() => { if (open) fetchLogs() }, [open]) + + const fetchLogs = async () => { + setLoading(true) + try { + const res = await axios.get(`/api/litters/${litterId}/puppies/${puppy.id}/logs`) + const parsed = res.data.map(l => { + try { return { ...l, _data: JSON.parse(l.description) } } catch { return { ...l, _data: {} } } + }) + setLogs(parsed) + } catch (e) { console.error(e) } + finally { setLoading(false) } + } + + const handleAdd = async () => { + if (!form.record_date) return + setSaving(true) + try { + await axios.post(`/api/litters/${litterId}/puppies/${puppy.id}/logs`, form) + setShowAdd(false) + setForm(f => ({ ...f, weight_oz: '', weight_lbs: '', notes: '' })) + fetchLogs() + } catch (e) { console.error(e) } + finally { setSaving(false) } + } + + const handleDelete = async (logId) => { + if (!window.confirm('Delete this log entry?')) return + try { + await axios.delete(`/api/litters/${litterId}/puppies/${puppy.id}/logs/${logId}`) + fetchLogs() + } catch (e) { console.error(e) } + } + + const TYPES = [ + { value: 'weight_log', label: '⚖️ Weight Check' }, + { value: 'health_note', label: '📝 Health Note' }, + { value: 'deworming', label: '🐛 Deworming' }, + { value: 'vaccination', label: '💉 Vaccination' }, + ] + + return ( +
Loading...
No logs yet.
- Bred: {new Date(litter.breeding_date).toLocaleDateString()} - {litter.whelping_date && ` • Whelped: ${new Date(litter.whelping_date).toLocaleDateString()}`} + Bred: {new Date(litter.breeding_date + 'T00:00:00').toLocaleDateString()} + {litter.whelping_date && ` • Whelped: ${new Date(litter.whelping_date + 'T00:00:00').toLocaleDateString()}`}
No puppies linked yet. Add puppies to this litter.
- Will default to whelping date: {new Date(litter.whelping_date).toLocaleDateString()} + Will default to whelping date: {new Date(litter.whelping_date + 'T00:00:00').toLocaleDateString()}