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 designerSchema = z.object({
description: z.string().optional(), description: z.string().optional(),
person_type: z.enum(['company', 'individual', 'firm', 'organization']), person_type: z.enum(['company', 'individual', 'firm', 'organization']),
website_url: z.string().url().optional().or(z.literal('')), 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(), headquarters_location: z.string().optional(),
images: z.object({ images: z.object({
uploaded: z.array(z.object({ uploaded: z.array(z.object({
@@ -147,7 +152,7 @@ export function DesignerForm({ onSubmit, onCancel, initialData }: DesignerFormPr
type="number" type="number"
min="1800" min="1800"
max={new Date().getFullYear()} max={new Date().getFullYear()}
{...register('founded_year', { valueAsNumber: true })} {...register('founded_year')}
placeholder="e.g. 1972" placeholder="e.g. 1972"
/> />
{errors.founded_year && ( {errors.founded_year && (

View File

@@ -20,7 +20,12 @@ const manufacturerSchema = z.object({
description: z.string().optional(), description: z.string().optional(),
person_type: z.enum(['company', 'individual', 'firm', 'organization']), person_type: z.enum(['company', 'individual', 'firm', 'organization']),
website_url: z.string().url().optional().or(z.literal('')), 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(), headquarters_location: z.string().optional(),
images: z.object({ images: z.object({
uploaded: z.array(z.object({ uploaded: z.array(z.object({
@@ -147,7 +152,7 @@ export function ManufacturerForm({ onSubmit, onCancel, initialData }: Manufactur
type="number" type="number"
min="1800" min="1800"
max={new Date().getFullYear()} max={new Date().getFullYear()}
{...register('founded_year', { valueAsNumber: true })} {...register('founded_year')}
placeholder="e.g. 1972" placeholder="e.g. 1972"
/> />
{errors.founded_year && ( {errors.founded_year && (

View File

@@ -20,7 +20,12 @@ const operatorSchema = z.object({
description: z.string().optional(), description: z.string().optional(),
person_type: z.enum(['company', 'individual', 'firm', 'organization']), person_type: z.enum(['company', 'individual', 'firm', 'organization']),
website_url: z.string().url().optional().or(z.literal('')), 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(), headquarters_location: z.string().optional(),
images: z.object({ images: z.object({
uploaded: z.array(z.object({ uploaded: z.array(z.object({
@@ -147,7 +152,7 @@ export function OperatorForm({ onSubmit, onCancel, initialData }: OperatorFormPr
type="number" type="number"
min="1800" min="1800"
max={new Date().getFullYear()} max={new Date().getFullYear()}
{...register('founded_year', { valueAsNumber: true })} {...register('founded_year')}
placeholder="e.g. 1972" placeholder="e.g. 1972"
/> />
{errors.founded_year && ( {errors.founded_year && (

View File

@@ -20,7 +20,12 @@ const propertyOwnerSchema = z.object({
description: z.string().optional(), description: z.string().optional(),
person_type: z.enum(['company', 'individual', 'firm', 'organization']), person_type: z.enum(['company', 'individual', 'firm', 'organization']),
website_url: z.string().url().optional().or(z.literal('')), 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(), headquarters_location: z.string().optional(),
images: z.object({ images: z.object({
uploaded: z.array(z.object({ uploaded: z.array(z.object({
@@ -147,7 +152,7 @@ export function PropertyOwnerForm({ onSubmit, onCancel, initialData }: PropertyO
type="number" type="number"
min="1800" min="1800"
max={new Date().getFullYear()} max={new Date().getFullYear()}
{...register('founded_year', { valueAsNumber: true })} {...register('founded_year')}
placeholder="e.g. 1972" placeholder="e.g. 1972"
/> />
{errors.founded_year && ( {errors.founded_year && (