mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 22:51:13 -05:00
Refactor: Implement datetime standardization
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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)"
|
||||
|
||||
@@ -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)"
|
||||
|
||||
@@ -14,6 +14,7 @@ import { supabase } from '@/integrations/supabase/client';
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
import { PhotoUpload } from '@/components/upload/PhotoUpload';
|
||||
import { StarRating } from './StarRating';
|
||||
import { toDateOnly } from '@/lib/dateUtils';
|
||||
const reviewSchema = z.object({
|
||||
rating: z.number().min(0.5).max(5).multipleOf(0.5),
|
||||
title: z.string().optional(),
|
||||
@@ -175,7 +176,7 @@ export function ReviewForm({
|
||||
<Label>Visit Date</Label>
|
||||
<DatePicker
|
||||
date={watch('visit_date') ? new Date(watch('visit_date')) : undefined}
|
||||
onSelect={(date) => setValue('visit_date', date ? date.toISOString().split('T')[0] : undefined)}
|
||||
onSelect={(date) => setValue('visit_date', date ? toDateOnly(date) : undefined)}
|
||||
placeholder="When did you visit?"
|
||||
disableFuture={true}
|
||||
fromYear={1950}
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { toDateOnly, toDateWithPrecision } from "@/lib/dateUtils";
|
||||
|
||||
export type DatePrecision = 'day' | 'month' | 'year';
|
||||
|
||||
@@ -70,11 +71,11 @@ export function FlexibleDateInput({
|
||||
let newDate: Date;
|
||||
switch (newPrecision) {
|
||||
case 'year':
|
||||
newDate = new Date(year, 0, 1); // January 1st
|
||||
newDate = new Date(year, 0, 1); // January 1st (local timezone)
|
||||
setYearValue(year.toString());
|
||||
break;
|
||||
case 'month':
|
||||
newDate = new Date(year, month, 1); // 1st of month
|
||||
newDate = new Date(year, month, 1); // 1st of month (local timezone)
|
||||
break;
|
||||
case 'day':
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user