Fix date input normalization

This commit is contained in:
gpt-engineer-app[bot]
2025-11-05 16:21:22 +00:00
parent 5a61a2b49e
commit c966b6c5ee
4 changed files with 19 additions and 23 deletions

View File

@@ -19,7 +19,7 @@ import { FlexibleDateInput, type DatePrecision } from '@/components/ui/flexible-
import { useAuth } from '@/hooks/useAuth';
import { toast } from 'sonner';
import { handleError } from '@/lib/errorHandler';
import { toDateOnly, parseDateOnly } from '@/lib/dateUtils';
import { toDateOnly, parseDateOnly, toDateWithPrecision } from '@/lib/dateUtils';
import type { UploadedImage } from '@/types/company';
// Zod output type (after transformation)
@@ -56,7 +56,7 @@ export function ManufacturerForm({ onSubmit, onCancel, initialData }: Manufactur
person_type: initialData?.person_type || ('company' as const),
website_url: initialData?.website_url || '',
founded_year: initialData?.founded_year ? String(initialData.founded_year) : '',
founded_date: initialData?.founded_date || (initialData?.founded_year ? `${initialData.founded_year}-01-01` : ''),
founded_date: initialData?.founded_date || (initialData?.founded_year ? `${initialData.founded_year}-01-01` : undefined),
founded_date_precision: initialData?.founded_date_precision || (initialData?.founded_year ? ('year' as const) : ('day' as const)),
headquarters_location: initialData?.headquarters_location || '',
source_url: initialData?.source_url || '',
@@ -178,11 +178,7 @@ export function ManufacturerForm({ onSubmit, onCancel, initialData }: Manufactur
})()}
precision={(watch('founded_date_precision') as DatePrecision) || 'year'}
onChange={(date, precision) => {
if (date && typeof date === 'string') {
setValue('founded_date', toDateOnly(date), { shouldValidate: true });
} else {
setValue('founded_date', '', { shouldValidate: true });
}
setValue('founded_date', date ? toDateWithPrecision(date, precision) : undefined, { shouldValidate: true });
setValue('founded_date_precision', precision);
}}
label="Founded Date"