diff --git a/client/src/components/DogForm.jsx b/client/src/components/DogForm.jsx index 24b6f24..34a2b20 100644 --- a/client/src/components/DogForm.jsx +++ b/client/src/components/DogForm.jsx @@ -1,8 +1,8 @@ import { useState, useEffect } from 'react' -import { X, Award } from 'lucide-react' +import { X, Award, ExternalLink } from 'lucide-react' import axios from 'axios' -function DogForm({ dog, onClose, onSave }) { +function DogForm({ dog, onClose, onSave, isExternal = false }) { const [formData, setFormData] = useState({ name: '', registration_number: '', @@ -16,6 +16,7 @@ function DogForm({ dog, onClose, onSave }) { dam_id: null, litter_id: null, is_champion: false, + is_external: isExternal ? 1 : 0, }) const [dogs, setDogs] = useState([]) const [litters, setLitters] = useState([]) @@ -24,9 +25,14 @@ function DogForm({ dog, onClose, onSave }) { const [useManualParents, setUseManualParents] = useState(true) const [littersAvailable, setLittersAvailable] = useState(false) + // Derive effective external state (editing an existing external dog or explicitly flagged) + const effectiveExternal = isExternal || (dog && dog.is_external) + useEffect(() => { - fetchDogs() - fetchLitters() + if (!effectiveExternal) { + fetchDogs() + fetchLitters() + } if (dog) { setFormData({ name: dog.name || '', @@ -41,6 +47,7 @@ function DogForm({ dog, onClose, onSave }) { dam_id: dog.dam?.id || null, litter_id: dog.litter_id || null, is_champion: !!dog.is_champion, + is_external: dog.is_external ?? (isExternal ? 1 : 0), }) setUseManualParents(!dog.litter_id) } @@ -104,9 +111,10 @@ function DogForm({ dog, onClose, onSave }) { const submitData = { ...formData, is_champion: formData.is_champion ? 1 : 0, - sire_id: formData.sire_id || null, - dam_id: formData.dam_id || null, - litter_id: useManualParents ? null : (formData.litter_id || null), + is_external: effectiveExternal ? 1 : 0, + sire_id: effectiveExternal ? null : (formData.sire_id || null), + dam_id: effectiveExternal ? null : (formData.dam_id || null), + litter_id: (effectiveExternal || useManualParents) ? null : (formData.litter_id || null), registration_number: formData.registration_number || null, birth_date: formData.birth_date || null, color: formData.color || null, @@ -133,10 +141,31 @@ function DogForm({ dog, onClose, onSave }) {