Refactor: Restore type safety in forms

This commit is contained in:
gpt-engineer-app[bot]
2025-10-12 16:28:28 +00:00
parent dd079bd5a5
commit 3ba2077e0a
4 changed files with 109 additions and 28 deletions

View File

@@ -21,6 +21,26 @@ import { useAuth } from '@/hooks/useAuth';
import { toast } from 'sonner';
import { useNavigate } from 'react-router-dom';
// Raw form input state (before Zod transformation)
interface DesignerFormInput {
name: string;
slug: string;
company_type: 'designer' | 'manufacturer' | 'operator' | 'property_owner';
description?: string;
person_type: 'company' | 'individual' | 'firm' | 'organization';
founded_year?: string;
founded_date?: string;
founded_date_precision?: 'day' | 'month' | 'year';
headquarters_location?: string;
website_url?: string;
images?: {
uploaded: any[];
banner_assignment?: number | null;
card_assignment?: number | null;
};
}
// Zod output type (after transformation)
type DesignerFormData = z.infer<typeof entitySchemas.designer>;
interface DesignerFormProps {
@@ -51,8 +71,9 @@ export function DesignerForm({ onSubmit, onCancel, initialData }: DesignerFormPr
defaultValues: {
name: initialData?.name || '',
slug: initialData?.slug || '',
company_type: 'designer' as const,
description: initialData?.description || '',
person_type: initialData?.person_type || 'company',
person_type: initialData?.person_type || ('company' as const),
website_url: initialData?.website_url || '',
founded_year: initialData?.founded_year ? String(initialData.founded_year) : '',
headquarters_location: initialData?.headquarters_location || '',
@@ -78,13 +99,13 @@ export function DesignerForm({ onSubmit, onCancel, initialData }: DesignerFormPr
setIsSubmitting(true);
try {
if (initialData?.id) {
await submitDesignerUpdate(initialData.id, data as unknown as DesignerFormData, user.id);
toast.success('Designer update submitted for review');
} else {
await submitDesignerCreation(data as unknown as DesignerFormData, user.id);
toast.success('Designer submitted for review');
}
if (initialData?.id) {
await submitDesignerUpdate(initialData.id, data, user.id);
toast.success('Designer update submitted for review');
} else {
await submitDesignerCreation(data, user.id);
toast.success('Designer submitted for review');
}
onCancel();
} catch (error) {
console.error('Submission error:', error);