mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 11:11:13 -05:00
Refactor: Restore type safety in forms
This commit is contained in:
@@ -20,6 +20,24 @@ import { useAuth } from '@/hooks/useAuth';
|
||||
import { toast } from 'sonner';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
// Raw form input state (before Zod transformation)
|
||||
interface PropertyOwnerFormInput {
|
||||
name: string;
|
||||
slug: string;
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
const propertyOwnerSchema = z.object({
|
||||
name: z.string().min(1, 'Name is required'),
|
||||
slug: z.string().min(1, 'Slug is required'),
|
||||
@@ -81,7 +99,7 @@ export function PropertyOwnerForm({ onSubmit, onCancel, initialData }: PropertyO
|
||||
name: initialData?.name || '',
|
||||
slug: initialData?.slug || '',
|
||||
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 || '',
|
||||
@@ -108,10 +126,10 @@ export function PropertyOwnerForm({ onSubmit, onCancel, initialData }: PropertyO
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
if (initialData?.id) {
|
||||
await submitPropertyOwnerUpdate(initialData.id, data as unknown as PropertyOwnerFormData, user.id);
|
||||
await submitPropertyOwnerUpdate(initialData.id, data, user.id);
|
||||
toast.success('Property owner update submitted for review');
|
||||
} else {
|
||||
await submitPropertyOwnerCreation(data as unknown as PropertyOwnerFormData, user.id);
|
||||
await submitPropertyOwnerCreation(data, user.id);
|
||||
toast.success('Property owner submitted for review');
|
||||
}
|
||||
onCancel();
|
||||
|
||||
Reference in New Issue
Block a user