Refactor: Implement type safety plan

This commit is contained in:
gpt-engineer-app[bot]
2025-10-17 14:35:15 +00:00
parent 921abb63a1
commit 0db54b402b
12 changed files with 290 additions and 38 deletions

View File

@@ -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);
};