0.8.0.0
This commit is contained in:
@@ -96,46 +96,7 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
|
||||
const [errors, setErrors] = useState<string[]>([])
|
||||
|
||||
// 监听 initialData 变化,更新 formData
|
||||
useEffect(() => {
|
||||
if (!initialData) return
|
||||
|
||||
setFormData((prev) => {
|
||||
const normalizedPhotos: FamilyPhoto[] = initialData.photos && initialData.photos.length > 0
|
||||
? initialData.photos
|
||||
: (initialData.photoIds || []).map((url) => ({
|
||||
url,
|
||||
uploadedAt: initialData.updatedAt || new Date().toISOString(),
|
||||
}))
|
||||
|
||||
// 优先使用 initialData 中的 motherId,如果没有才使用之前的值
|
||||
const newMotherId = initialData.motherId !== undefined ? initialData.motherId : prev.motherId
|
||||
console.log('Calculating new motherId:', {
|
||||
initial: initialData.motherId,
|
||||
prev: prev.motherId,
|
||||
result: newMotherId,
|
||||
hasInitialMother: initialData.motherId !== undefined
|
||||
})
|
||||
|
||||
return {
|
||||
...prev,
|
||||
...initialData,
|
||||
// 确保特定字段被正确更新
|
||||
gender: initialData.gender ? (initialData.gender.toUpperCase() as "MALE" | "FEMALE") : prev.gender,
|
||||
spouseIds: initialData.spouseIds || prev.spouseIds || [],
|
||||
childrenIds: initialData.childrenIds || prev.childrenIds || [],
|
||||
tags: initialData.tags || prev.tags || [],
|
||||
fatherId: initialData.fatherId || prev.fatherId,
|
||||
motherId: newMotherId,
|
||||
photos: initialData.photos ? normalizedPhotos : prev.photos,
|
||||
photoIds: initialData.photoIds || (initialData.photos ? normalizedPhotos.map((p) => p.url) : prev.photoIds),
|
||||
}
|
||||
})
|
||||
}, [initialData])
|
||||
|
||||
const handleChange = (field: keyof FamilyMember, value: any) => {
|
||||
console.log('handleChange:', field, value)
|
||||
|
||||
setFormData((prev) => {
|
||||
const newData = { ...prev, [field]: value }
|
||||
|
||||
@@ -149,9 +110,8 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
const father = existingMembers.find(m => m.id === value)
|
||||
if (father && father.spouseIds && father.spouseIds.length > 0) {
|
||||
const motherId = father.spouseIds[0]
|
||||
if (!newData.motherId) { // Only auto-set if motherId is not already present
|
||||
if (!newData.motherId) {
|
||||
newData.motherId = motherId
|
||||
console.log('Auto-set mother from father:', { fatherId: value, motherId })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,9 +121,8 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
const mother = existingMembers.find(m => m.id === value)
|
||||
if (mother && mother.spouseIds && mother.spouseIds.length > 0) {
|
||||
const fatherId = mother.spouseIds[0]
|
||||
if (!newData.fatherId) { // Only auto-set if fatherId is not already present
|
||||
if (!newData.fatherId) {
|
||||
newData.fatherId = fatherId
|
||||
console.log('Auto-set father from mother:', { motherId: value, fatherId })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -289,13 +248,6 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
}
|
||||
|
||||
const potentialRelatives = existingMembers.filter((m) => m.id !== formData.id)
|
||||
|
||||
// 调试日志
|
||||
console.log('MemberForm render:', {
|
||||
motherId: formData.motherId,
|
||||
existingMembersCount: existingMembers.length,
|
||||
motherInList: existingMembers.find(m => m.id === formData.motherId)
|
||||
})
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="w-full">
|
||||
@@ -430,18 +382,20 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="fatherId">父亲</Label>
|
||||
{isFounder ? (
|
||||
<Input
|
||||
placeholder="填写父亲姓名"
|
||||
value={formData.spouseFatherName || ""}
|
||||
onChange={(e) => handleChange("spouseFatherName", e.target.value)}
|
||||
/>
|
||||
<div className="space-y-2">
|
||||
<Input
|
||||
placeholder="填写父亲姓名"
|
||||
value={formData.spouseFatherName || ""}
|
||||
onChange={(e) => handleChange("spouseFatherName", e.target.value)}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">始祖为第一世,父母信息仅记录姓名</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex gap-2">
|
||||
<Select
|
||||
value={formData.fatherId || "none"}
|
||||
onValueChange={(val) => {
|
||||
const newValue = val === "none" ? undefined : val
|
||||
console.log('Father select change:', { val, newValue })
|
||||
handleChange("fatherId", newValue)
|
||||
}}
|
||||
>
|
||||
@@ -480,18 +434,20 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="motherId">母亲</Label>
|
||||
{isFounder ? (
|
||||
<Input
|
||||
placeholder="填写母亲姓名"
|
||||
value={formData.spouseMotherName || ""}
|
||||
onChange={(e) => handleChange("spouseMotherName", e.target.value)}
|
||||
/>
|
||||
<div className="space-y-2">
|
||||
<Input
|
||||
placeholder="填写母亲姓名"
|
||||
value={formData.spouseMotherName || ""}
|
||||
onChange={(e) => handleChange("spouseMotherName", e.target.value)}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">始祖为第一世,父母信息仅记录姓名</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex gap-2">
|
||||
<Select
|
||||
value={formData.motherId || "none"}
|
||||
onValueChange={(val) => {
|
||||
const newValue = val === "none" ? undefined : val
|
||||
console.log('Mother select change:', { val, newValue })
|
||||
handleChange("motherId", newValue)
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user