mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 06:31:13 -05:00
feat: Implement phases 5, 6, and 7
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import * as z from 'zod';
|
||||
import { entitySchemas } from '@/lib/entityValidationSchemas';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
@@ -14,37 +15,7 @@ import { useCompanyHeadquarters } from '@/hooks/useAutocompleteData';
|
||||
import { useUserRole } from '@/hooks/useUserRole';
|
||||
import { EntityMultiImageUploader, ImageAssignments } from '@/components/upload/EntityMultiImageUploader';
|
||||
|
||||
const operatorSchema = z.object({
|
||||
name: z.string().min(1, 'Name is required'),
|
||||
slug: z.string().min(1, 'Slug is required'),
|
||||
description: z.string().optional(),
|
||||
person_type: z.enum(['company', 'individual', 'firm', 'organization']),
|
||||
website_url: z.string().url().optional().or(z.literal('')),
|
||||
founded_year: z.string()
|
||||
.optional()
|
||||
.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(),
|
||||
images: z.object({
|
||||
uploaded: z.array(z.object({
|
||||
url: z.string(),
|
||||
cloudflare_id: z.string().optional(),
|
||||
file: z.any().optional(),
|
||||
isLocal: z.boolean().optional(),
|
||||
caption: z.string().optional()
|
||||
})),
|
||||
banner_assignment: z.number().nullable().optional(),
|
||||
card_assignment: z.number().nullable().optional()
|
||||
}).optional()
|
||||
});
|
||||
|
||||
type OperatorFormData = z.infer<typeof operatorSchema>;
|
||||
type OperatorFormData = z.infer<typeof entitySchemas.operator>;
|
||||
|
||||
// Input type for the form (before transformation)
|
||||
type OperatorFormInput = {
|
||||
@@ -89,7 +60,7 @@ export function OperatorForm({ onSubmit, onCancel, initialData }: OperatorFormPr
|
||||
watch,
|
||||
formState: { errors }
|
||||
} = useForm<OperatorFormInput>({
|
||||
resolver: zodResolver(operatorSchema),
|
||||
resolver: zodResolver(entitySchemas.operator),
|
||||
defaultValues: {
|
||||
name: initialData?.name || '',
|
||||
slug: initialData?.slug || '',
|
||||
|
||||
Reference in New Issue
Block a user