mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 05:51:23 -05:00
Fix: Type safety and unit validation
This commit is contained in:
@@ -29,8 +29,8 @@ import { useManufacturers, useRideModels } from '@/hooks/useAutocompleteData';
|
||||
import { useUserRole } from '@/hooks/useUserRole';
|
||||
import { ManufacturerForm } from './ManufacturerForm';
|
||||
import { RideModelForm } from './RideModelForm';
|
||||
import { TechnicalSpecsEditor } from './editors/TechnicalSpecsEditor';
|
||||
import { CoasterStatsEditor } from './editors/CoasterStatsEditor';
|
||||
import { TechnicalSpecsEditor, validateTechnicalSpecs } from './editors/TechnicalSpecsEditor';
|
||||
import { CoasterStatsEditor, validateCoasterStats } from './editors/CoasterStatsEditor';
|
||||
import { FormerNamesEditor } from './editors/FormerNamesEditor';
|
||||
import {
|
||||
convertValueToMetric,
|
||||
@@ -222,6 +222,31 @@ export function RideForm({ onSubmit, onCancel, initialData, isEditing = false }:
|
||||
|
||||
const handleFormSubmit = async (data: RideFormData) => {
|
||||
try {
|
||||
// Validate coaster stats
|
||||
if (coasterStats && coasterStats.length > 0) {
|
||||
const statsValidation = validateCoasterStats(coasterStats);
|
||||
if (!statsValidation.valid) {
|
||||
toast({
|
||||
title: 'Invalid coaster statistics',
|
||||
description: statsValidation.errors.join(', '),
|
||||
variant: 'destructive'
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate technical specs
|
||||
if (technicalSpecs && technicalSpecs.length > 0) {
|
||||
const specsValidation = validateTechnicalSpecs(technicalSpecs);
|
||||
if (!specsValidation.valid) {
|
||||
toast({
|
||||
title: 'Invalid technical specifications',
|
||||
description: specsValidation.errors.join(', '),
|
||||
variant: 'destructive'
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert form values back to metric for storage
|
||||
const metricData = {
|
||||
@@ -349,7 +374,7 @@ export function RideForm({ onSubmit, onCancel, initialData, isEditing = false }:
|
||||
<div className="space-y-2">
|
||||
<Label>Status *</Label>
|
||||
<Select
|
||||
onValueChange={(value) => setValue('status', value as any)}
|
||||
onValueChange={(value) => setValue('status', value as "operating" | "closed_permanently" | "closed_temporarily" | "under_construction" | "relocated" | "stored" | "demolished")}
|
||||
defaultValue={initialData?.status || 'operating'}
|
||||
>
|
||||
<SelectTrigger>
|
||||
|
||||
Reference in New Issue
Block a user