refactor: move person domain components and utils to lib/person/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
39
frontend/src/lib/person/person-validation.ts
Normal file
39
frontend/src/lib/person/person-validation.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { m } from '$lib/paraglide/messages.js';
|
||||
|
||||
export const PERSON_TYPES = ['PERSON', 'INSTITUTION', 'GROUP', 'UNKNOWN'] as const;
|
||||
export type PersonType = (typeof PERSON_TYPES)[number];
|
||||
|
||||
export type PersonFormData = {
|
||||
personType?: string | null;
|
||||
title?: string | null;
|
||||
firstName?: string | null;
|
||||
lastName: string;
|
||||
alias?: string | null;
|
||||
birthYear?: number | null;
|
||||
deathYear?: number | null;
|
||||
notes?: string | null;
|
||||
};
|
||||
|
||||
export function normalizePersonType(raw: string | undefined | null): PersonType {
|
||||
return raw === 'SKIP' ? 'UNKNOWN' : ((raw ?? 'PERSON') as PersonType);
|
||||
}
|
||||
|
||||
export type PersonValidationKey =
|
||||
| 'validation_last_name_required'
|
||||
| 'validation_first_name_required';
|
||||
|
||||
export function resolveValidationMessage(key: PersonValidationKey): string {
|
||||
return key === 'validation_last_name_required'
|
||||
? m.validation_last_name_required()
|
||||
: m.validation_first_name_required();
|
||||
}
|
||||
|
||||
export function validatePersonFields(
|
||||
personType: string,
|
||||
firstName: string | undefined | null,
|
||||
lastName: string | undefined | null
|
||||
): PersonValidationKey | null {
|
||||
if (!lastName) return 'validation_last_name_required';
|
||||
if (personType === 'PERSON' && !firstName) return 'validation_first_name_required';
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user