Refactor: Implement complete plan

This commit is contained in:
gpt-engineer-app[bot]
2025-10-17 14:04:57 +00:00
parent a89a740611
commit a2e05c5080
10 changed files with 258 additions and 68 deletions

View File

@@ -0,0 +1,52 @@
import { useQuery } from '@tanstack/react-query';
import { supabase } from '@/integrations/supabase/client';
export interface TechnicalSpecification {
id: string;
entity_type: 'ride' | 'ride_model';
entity_id: string;
spec_name: string;
spec_value: string;
spec_unit?: string | null;
category?: string | null;
display_order: number;
created_at: string;
}
export function useTechnicalSpecifications(
entityType: 'ride' | 'ride_model',
entityId: string | undefined
) {
return useQuery({
queryKey: ['technical-specifications', entityType, entityId],
queryFn: async () => {
if (!entityId) return [];
const tableName = entityType === 'ride'
? 'ride_technical_specifications'
: 'ride_model_technical_specifications';
const idColumn = entityType === 'ride' ? 'ride_id' : 'ride_model_id';
const { data, error } = await (supabase as any)
.from(tableName)
.select('*')
.eq(idColumn, entityId)
.order('display_order');
if (error) throw error;
return (data || []).map((spec: any) => ({
id: spec.id,
entity_type: entityType,
entity_id: entityId,
spec_name: spec.spec_name,
spec_value: spec.spec_value,
spec_unit: spec.spec_unit || null,
category: spec.category || null,
display_order: spec.display_order,
created_at: spec.created_at,
})) as TechnicalSpecification[];
},
enabled: !!entityId
});
}