Fix designer form defaultValues

This commit is contained in:
gpt-engineer-app[bot]
2025-10-13 18:11:47 +00:00
parent 56dfbd087f
commit ca2ccd8b88

View File

@@ -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<typeof propertyOwnerSchema>;
// Zod output type (after transformation)
type PropertyOwnerFormData = z.infer<typeof entitySchemas.property_owner>;
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 || '',