mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 12:31:13 -05:00
Refactor: Implement entity type safety plan
This commit is contained in:
@@ -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"
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user