mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 21:11:12 -05:00
Improve form validation and image handling for entities
Refactor validation logic for 'founded_year' in multiple form components, enhance image cleanup in `EntityMultiImageUploader`, update `useEntityVersions` to prevent race conditions, improve error handling for recent searches in `useSearch`, refine rate limiting logic in `detect-location` Supabase function, and update CORS configuration for `upload-image` Supabase function. Replit-Commit-Author: Agent Replit-Commit-Session-Id: b9af4867-23a7-43cc-baeb-4a97f66b4150 Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
@@ -22,8 +22,12 @@ const operatorSchema = z.object({
|
||||
website_url: z.string().url().optional().or(z.literal('')),
|
||||
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()), {
|
||||
.transform(val => {
|
||||
if (!val || val.trim() === '') return undefined;
|
||||
const num = Number(val);
|
||||
return isNaN(num) ? undefined : num;
|
||||
})
|
||||
.refine(val => val === undefined || (typeof val === 'number' && val >= 1800 && val <= new Date().getFullYear()), {
|
||||
message: "Founded year must be between 1800 and current year"
|
||||
}),
|
||||
headquarters_location: z.string().optional(),
|
||||
@@ -70,10 +74,10 @@ export function OperatorForm({ onSubmit, onCancel, initialData }: OperatorFormPr
|
||||
description: initialData?.description || '',
|
||||
person_type: initialData?.person_type || 'company',
|
||||
website_url: initialData?.website_url || '',
|
||||
founded_year: initialData?.founded_year || undefined,
|
||||
founded_year: initialData?.founded_year ? String(initialData.founded_year) : '',
|
||||
headquarters_location: initialData?.headquarters_location || '',
|
||||
images: initialData?.images || { uploaded: [] }
|
||||
}
|
||||
} as Partial<OperatorFormData>
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user