Refactor: Implement entity type safety plan

This commit is contained in:
gpt-engineer-app[bot]
2025-10-16 13:48:41 +00:00
parent 2106142150
commit 4efdeaa104
9 changed files with 34 additions and 38 deletions

View File

@@ -22,7 +22,7 @@ export default function ManufacturerModels() {
const { user } = useAuth();
const { requireAuth } = useAuthModal();
const [manufacturer, setManufacturer] = useState<Company | null>(null);
const [models, setModels] = useState<RideModel[]>([]);
const [models, setModels] = useState<RideModelWithCount[]>([]);
const [loading, setLoading] = useState(true);
const [searchQuery, setSearchQuery] = useState('');
const [sortBy, setSortBy] = useState('name');
@@ -68,12 +68,12 @@ export default function ManufacturerModels() {
if (modelsError) throw modelsError;
// Transform data to include ride count
const modelsWithCounts = (modelsData || []).map(model => ({
...model,
ride_count: Array.isArray(model.rides) ? model.rides[0]?.count || 0 : 0
}));
setModels(modelsWithCounts as RideModel[]);
const modelsWithCounts: RideModelWithCount[] = (modelsData || []).map(model => ({
...model,
ride_count: Array.isArray(model.rides) ? model.rides[0]?.count || 0 : 0
}));
setModels(modelsWithCounts);
}
} catch (error) {
console.error('Error fetching data:', error);
@@ -95,10 +95,6 @@ export default function ManufacturerModels() {
const handleCreateSubmit = async (data: any) => {
try {
if (!user || !manufacturer) {
return;
}
if (!manufacturer) {
toast({
title: "Error",
@@ -123,10 +119,11 @@ export default function ManufacturerModels() {
setIsCreateModalOpen(false);
fetchData();
} catch (error: any) {
} catch (error) {
const message = error instanceof Error ? error.message : "Failed to submit ride model.";
toast({
title: "Error",
description: error.message || "Failed to submit ride model.",
description: message,
variant: "destructive"
});
}