From ca2ccd8b880c47ad58701cd3aae5dea985e347b5 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Mon, 13 Oct 2025 18:11:47 +0000 Subject: [PATCH] Fix designer form defaultValues --- src/components/admin/PropertyOwnerForm.tsx | 38 ++++------------------ 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/src/components/admin/PropertyOwnerForm.tsx b/src/components/admin/PropertyOwnerForm.tsx index 6ab088c8..85d70233 100644 --- a/src/components/admin/PropertyOwnerForm.tsx +++ b/src/components/admin/PropertyOwnerForm.tsx @@ -2,6 +2,7 @@ import { useState } from 'react'; 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'; @@ -24,6 +25,7 @@ import { useNavigate } from 'react-router-dom'; interface PropertyOwnerFormInput { name: string; slug: string; + company_type: 'designer' | 'manufacturer' | 'operator' | 'property_owner'; description?: string; person_type: 'company' | 'individual' | 'firm' | 'organization'; founded_year?: string; @@ -38,37 +40,8 @@ interface PropertyOwnerFormInput { }; } -const propertyOwnerSchema = 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 PropertyOwnerFormData = z.infer; +// Zod output type (after transformation) +type PropertyOwnerFormData = z.infer; interface PropertyOwnerFormProps { onSubmit: (data: PropertyOwnerFormData) => void; @@ -94,10 +67,11 @@ export function PropertyOwnerForm({ onSubmit, onCancel, initialData }: PropertyO watch, formState: { errors } } = useForm({ - resolver: zodResolver(propertyOwnerSchema), + resolver: zodResolver(entitySchemas.property_owner), defaultValues: { name: initialData?.name || '', slug: initialData?.slug || '', + company_type: 'property_owner' as const, description: initialData?.description || '', person_type: initialData?.person_type || ('company' as const), website_url: initialData?.website_url || '',