mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 13:51:13 -05:00
Fix: Correct founded year validation
This commit is contained in:
@@ -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 && (
|
||||||
|
|||||||
@@ -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 && (
|
||||||
|
|||||||
@@ -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 && (
|
||||||
|
|||||||
@@ -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 && (
|
||||||
|
|||||||
Reference in New Issue
Block a user