mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 15:11:12 -05:00
Refactor: Implement type safety plan
This commit is contained in:
@@ -6,6 +6,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useUnitPreferences } from "@/hooks/useUnitPreferences";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
convertValueToMetric,
|
||||
convertValueFromMetric,
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
getMetricUnit,
|
||||
getDisplayUnit
|
||||
} from "@/lib/units";
|
||||
import { validateMetricUnit } from "@/lib/unitValidation";
|
||||
|
||||
interface CoasterStat {
|
||||
stat_name: string;
|
||||
@@ -83,7 +85,20 @@ export function CoasterStatsEditor({
|
||||
|
||||
const updateStat = (index: number, field: keyof CoasterStat, value: any) => {
|
||||
const newStats = [...stats];
|
||||
newStats[index] = { ...newStats[index], [field]: value };
|
||||
|
||||
// Ensure unit is metric when updating unit field
|
||||
if (field === 'unit' && value) {
|
||||
try {
|
||||
validateMetricUnit(value, 'Unit');
|
||||
newStats[index] = { ...newStats[index], [field]: value };
|
||||
} catch (error) {
|
||||
toast.error(`Invalid unit: ${value}. Please use metric units only (km/h, m, cm, kg, G, etc.)`);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
newStats[index] = { ...newStats[index], [field]: value };
|
||||
}
|
||||
|
||||
onChange(newStats);
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Label } from "@/components/ui/label";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useUnitPreferences } from "@/hooks/useUnitPreferences";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
convertValueToMetric,
|
||||
convertValueFromMetric,
|
||||
@@ -12,6 +13,7 @@ import {
|
||||
getMetricUnit,
|
||||
getDisplayUnit
|
||||
} from "@/lib/units";
|
||||
import { validateMetricUnit } from "@/lib/unitValidation";
|
||||
|
||||
interface TechnicalSpec {
|
||||
spec_name: string;
|
||||
@@ -62,7 +64,20 @@ export function TechnicalSpecsEditor({
|
||||
|
||||
const updateSpec = (index: number, field: keyof TechnicalSpec, value: any) => {
|
||||
const newSpecs = [...specs];
|
||||
newSpecs[index] = { ...newSpecs[index], [field]: value };
|
||||
|
||||
// Ensure unit is metric when updating unit field
|
||||
if (field === 'unit' && value) {
|
||||
try {
|
||||
validateMetricUnit(value, 'Unit');
|
||||
newSpecs[index] = { ...newSpecs[index], [field]: value };
|
||||
} catch (error) {
|
||||
toast.error(`Invalid unit: ${value}. Please use metric units only (m, km/h, cm, kg, celsius, etc.)`);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
newSpecs[index] = { ...newSpecs[index], [field]: value };
|
||||
}
|
||||
|
||||
onChange(newSpecs);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user