Refactor: Implement datetime standardization

This commit is contained in:
gpt-engineer-app[bot]
2025-10-13 17:32:58 +00:00
parent 29f4f3c2aa
commit 5feee9f4bc
7 changed files with 472 additions and 8 deletions

View File

@@ -20,6 +20,7 @@ import { submitManufacturerCreation, submitManufacturerUpdate } from '@/lib/enti
import { useAuth } from '@/hooks/useAuth';
import { toast } from 'sonner';
import { useNavigate } from 'react-router-dom';
import { toDateOnly } from '@/lib/dateUtils';
// Raw form input state (before Zod transformation)
interface ManufacturerFormInput {
@@ -187,7 +188,7 @@ export function ManufacturerForm({ onSubmit, onCancel, initialData }: Manufactur
value={watch('founded_date') ? new Date(watch('founded_date')) : undefined}
precision={(watch('founded_date_precision') as DatePrecision) || 'year'}
onChange={(date, precision) => {
setValue('founded_date', date ? date.toISOString().split('T')[0] : undefined);
setValue('founded_date', date ? toDateOnly(date) : undefined);
setValue('founded_date_precision', precision);
}}
label="Founded Date"

View File

@@ -16,6 +16,7 @@ import { FlexibleDateInput, type DatePrecision } from '@/components/ui/flexible-
import { SlugField } from '@/components/ui/slug-field';
import { toast } from '@/hooks/use-toast';
import { MapPin, Save, X, Plus } from 'lucide-react';
import { toDateOnly } from '@/lib/dateUtils';
import { Badge } from '@/components/ui/badge';
import { Combobox } from '@/components/ui/combobox';
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';
@@ -286,7 +287,7 @@ export function ParkForm({ onSubmit, onCancel, initialData, isEditing = false }:
value={watch('opening_date') ? new Date(watch('opening_date')) : undefined}
precision={(watch('opening_date_precision') as DatePrecision) || 'day'}
onChange={(date, precision) => {
setValue('opening_date', date ? date.toISOString().split('T')[0] : undefined);
setValue('opening_date', date ? toDateOnly(date) : undefined);
setValue('opening_date_precision', precision);
}}
label="Opening Date"
@@ -299,7 +300,7 @@ export function ParkForm({ onSubmit, onCancel, initialData, isEditing = false }:
value={watch('closing_date') ? new Date(watch('closing_date')) : undefined}
precision={(watch('closing_date_precision') as DatePrecision) || 'day'}
onChange={(date, precision) => {
setValue('closing_date', date ? date.toISOString().split('T')[0] : undefined);
setValue('closing_date', date ? toDateOnly(date) : undefined);
setValue('closing_date_precision', precision);
}}
label="Closing Date (if applicable)"

View File

@@ -19,6 +19,7 @@ import { Combobox } from '@/components/ui/combobox';
import { SlugField } from '@/components/ui/slug-field';
import { toast } from '@/hooks/use-toast';
import { Plus, Zap, Save, X } from 'lucide-react';
import { toDateOnly } from '@/lib/dateUtils';
import { useUnitPreferences } from '@/hooks/useUnitPreferences';
import { useManufacturers, useRideModels } from '@/hooks/useAutocompleteData';
import { useUserRole } from '@/hooks/useUserRole';
@@ -493,7 +494,7 @@ export function RideForm({ onSubmit, onCancel, initialData, isEditing = false }:
value={watch('opening_date') ? new Date(watch('opening_date')) : undefined}
precision={(watch('opening_date_precision') as DatePrecision) || 'day'}
onChange={(date, precision) => {
setValue('opening_date', date ? date.toISOString().split('T')[0] : undefined);
setValue('opening_date', date ? toDateOnly(date) : undefined);
setValue('opening_date_precision', precision);
}}
label="Opening Date"
@@ -506,7 +507,7 @@ export function RideForm({ onSubmit, onCancel, initialData, isEditing = false }:
value={watch('closing_date') ? new Date(watch('closing_date')) : undefined}
precision={(watch('closing_date_precision') as DatePrecision) || 'day'}
onChange={(date, precision) => {
setValue('closing_date', date ? date.toISOString().split('T')[0] : undefined);
setValue('closing_date', date ? toDateOnly(date) : undefined);
setValue('closing_date_precision', precision);
}}
label="Closing Date (if applicable)"