Fix: Correct founded year validation

This commit is contained in:
gpt-engineer-app[bot]
2025-10-01 19:32:34 +00:00
parent 39119a013a
commit 5831705fe2
4 changed files with 28 additions and 8 deletions

View File

@@ -20,7 +20,12 @@ const operatorSchema = z.object({
description: z.string().optional(),
person_type: z.enum(['company', 'individual', 'firm', 'organization']),
website_url: z.string().url().optional().or(z.literal('')),
founded_year: z.number().min(1800).max(new Date().getFullYear()).optional(),
founded_year: z.string()
.optional()
.transform(val => val === '' || val === undefined ? undefined : Number(val))
.refine(val => val === undefined || (!isNaN(val) && val >= 1800 && val <= new Date().getFullYear()), {
message: "Founded year must be between 1800 and current year"
}),
headquarters_location: z.string().optional(),
images: z.object({
uploaded: z.array(z.object({
@@ -147,7 +152,7 @@ export function OperatorForm({ onSubmit, onCancel, initialData }: OperatorFormPr
type="number"
min="1800"
max={new Date().getFullYear()}
{...register('founded_year', { valueAsNumber: true })}
{...register('founded_year')}
placeholder="e.g. 1972"
/>
{errors.founded_year && (