refactor: Improve person creation and identification logic with optional fields handling

This commit refactors the person creation and identification logic to handle optional fields more effectively. The `date_of_birth` field in the `PersonCreateRequest` schema is now optional, and the frontend has been updated to trim whitespace from name fields before submission. Additionally, the identification logic has been enhanced to ensure that only non-empty names are considered valid. Documentation has been updated to reflect these changes.
This commit is contained in:
tanyar09
2025-11-27 13:02:02 -05:00
parent 709be7555a
commit 999e79f859
7 changed files with 88 additions and 54 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ export interface PersonCreateRequest {
last_name: string
middle_name?: string
maiden_name?: string
date_of_birth: string
date_of_birth?: string | null
}
export interface PersonUpdateRequest {
+21 -8
View File
@@ -82,8 +82,10 @@ export default function Identify() {
const restorationCompleteRef = useRef(false)
const canIdentify = useMemo(() => {
return Boolean((personId && currentFace) || (firstName && lastName && dob && currentFace))
}, [personId, firstName, lastName, dob, currentFace])
if (!currentFace) return false
if (personId) return true
return Boolean(firstName.trim() && lastName.trim())
}, [personId, firstName, lastName, currentFace])
const loadFaces = async (clearState: boolean = false, ignorePhotoIds: boolean = false) => {
setLoadingFaces(true)
@@ -589,6 +591,11 @@ export default function Identify() {
const handleIdentify = async () => {
if (!currentFace) return
setBusy(true)
const trimmedFirstName = firstName.trim()
const trimmedLastName = lastName.trim()
const trimmedMiddleName = middleName.trim()
const trimmedMaidenName = maidenName.trim()
const trimmedDob = dob.trim()
const additional = Object.entries(selectedSimilar)
.filter(([, v]) => v)
.map(([k]) => Number(k))
@@ -597,11 +604,17 @@ export default function Identify() {
if (personId) {
payload.person_id = personId
} else {
payload.first_name = firstName
payload.last_name = lastName
payload.middle_name = middleName || undefined
payload.maiden_name = maidenName || undefined
payload.date_of_birth = dob
payload.first_name = trimmedFirstName
payload.last_name = trimmedLastName
if (trimmedMiddleName) {
payload.middle_name = trimmedMiddleName
}
if (trimmedMaidenName) {
payload.maiden_name = trimmedMaidenName
}
if (trimmedDob) {
payload.date_of_birth = trimmedDob
}
}
await facesApi.identify(currentFace.id, payload)
// Optimistic: remove identified faces from list
@@ -948,7 +961,7 @@ export default function Identify() {
disabled={!!personId} />
</div>
<div className="col-span-2">
<label className="block text-sm font-medium text-gray-700">Date of Birth *</label>
<label className="block text-sm font-medium text-gray-700">Date of Birth (optional)</label>
<input type="date" value={dob} onChange={(e) => {
setDob(e.target.value)
setPersonId(undefined) // Clear person selection when typing