diff --git a/src/components/admin/DesignerForm.tsx b/src/components/admin/DesignerForm.tsx index 05ff35a8..7342563f 100644 --- a/src/components/admin/DesignerForm.tsx +++ b/src/components/admin/DesignerForm.tsx @@ -20,7 +20,12 @@ const designerSchema = 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 DesignerForm({ onSubmit, onCancel, initialData }: DesignerFormPr type="number" min="1800" max={new Date().getFullYear()} - {...register('founded_year', { valueAsNumber: true })} + {...register('founded_year')} placeholder="e.g. 1972" /> {errors.founded_year && ( diff --git a/src/components/admin/ManufacturerForm.tsx b/src/components/admin/ManufacturerForm.tsx index c3a4ad36..c685f7e5 100644 --- a/src/components/admin/ManufacturerForm.tsx +++ b/src/components/admin/ManufacturerForm.tsx @@ -20,7 +20,12 @@ const manufacturerSchema = 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 ManufacturerForm({ onSubmit, onCancel, initialData }: Manufactur type="number" min="1800" max={new Date().getFullYear()} - {...register('founded_year', { valueAsNumber: true })} + {...register('founded_year')} placeholder="e.g. 1972" /> {errors.founded_year && ( diff --git a/src/components/admin/OperatorForm.tsx b/src/components/admin/OperatorForm.tsx index 246427cf..e3c4fcc5 100644 --- a/src/components/admin/OperatorForm.tsx +++ b/src/components/admin/OperatorForm.tsx @@ -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 && ( diff --git a/src/components/admin/PropertyOwnerForm.tsx b/src/components/admin/PropertyOwnerForm.tsx index 9a2717c6..38105240 100644 --- a/src/components/admin/PropertyOwnerForm.tsx +++ b/src/components/admin/PropertyOwnerForm.tsx @@ -20,7 +20,12 @@ const propertyOwnerSchema = 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 PropertyOwnerForm({ onSubmit, onCancel, initialData }: PropertyO type="number" min="1800" max={new Date().getFullYear()} - {...register('founded_year', { valueAsNumber: true })} + {...register('founded_year')} placeholder="e.g. 1972" /> {errors.founded_year && (