0.3.0.4
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import type React from "react"
|
||||
|
||||
import { useState } from "react"
|
||||
import type { FamilyMember } from "@/types/family"
|
||||
import type { FamilyMember, FamilyPhoto } from "@/types/family"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
@@ -64,10 +64,19 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
spouseIds: [],
|
||||
childrenIds: [],
|
||||
tags: [],
|
||||
photos: [] as FamilyPhoto[],
|
||||
photoIds: [] as string[],
|
||||
}
|
||||
|
||||
if (!initialData) return defaults
|
||||
|
||||
const normalizedPhotos: FamilyPhoto[] = initialData.photos && initialData.photos.length > 0
|
||||
? initialData.photos
|
||||
: (initialData.photoIds || []).map((url) => ({
|
||||
url,
|
||||
uploadedAt: initialData.updatedAt || new Date().toISOString(),
|
||||
}))
|
||||
|
||||
return {
|
||||
...defaults,
|
||||
...initialData,
|
||||
@@ -77,6 +86,8 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
tags: initialData.tags || [],
|
||||
fatherId: initialData.fatherId || undefined,
|
||||
motherId: initialData.motherId || undefined,
|
||||
photos: normalizedPhotos,
|
||||
photoIds: initialData.photoIds || normalizedPhotos.map((photo) => photo.url),
|
||||
}
|
||||
})
|
||||
|
||||
@@ -117,6 +128,11 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
if (errors.length > 0) setErrors([])
|
||||
}
|
||||
|
||||
const handlePhotosChange = (photos: FamilyPhoto[]) => {
|
||||
handleChange("photos", photos)
|
||||
handleChange("photoIds", photos.map((photo) => photo.url))
|
||||
}
|
||||
|
||||
const handleSpouseAdd = (spouseId: string) => {
|
||||
if (!spouseId || spouseId === "none") return
|
||||
|
||||
@@ -852,8 +868,9 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<PhotoGallery
|
||||
photoIds={formData.photoIds || []}
|
||||
onChange={(photoIds) => handleChange("photoIds", photoIds)}
|
||||
photos={formData.photos}
|
||||
photoIds={formData.photoIds}
|
||||
onChange={handlePhotosChange}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user