'use client'; import { useState } from 'react'; import Button from '../ui/Button'; import { useInject } from '@/lib/di/hooks/useInject'; import { RACE_RESULTS_SERVICE_TOKEN } from '@/lib/di/tokens'; interface ImportResultsFormProps { raceId: string; onSuccess: (results: any[]) => void; onError: (error: string) => void; } export default function ImportResultsForm({ raceId, onSuccess, onError }: ImportResultsFormProps) { const [uploading, setUploading] = useState(false); const [error, setError] = useState(null); const raceResultsService = useInject(RACE_RESULTS_SERVICE_TOKEN); const handleFileChange = async (event: React.ChangeEvent) => { const file = event.target.files?.[0]; if (!file) return; setUploading(true); setError(null); try { const content = await file.text(); const results = (raceResultsService as any).parseAndTransformCSV(content, raceId); onSuccess(results); } catch (err) { const errorMessage = err instanceof Error ? err.message : 'Failed to parse CSV file'; setError(errorMessage); onError(errorMessage); } finally { setUploading(false); event.target.value = ''; } }; return ( <>

CSV format: driverId, position, fastestLap, incidents, startPosition

{error && (
Error: {error}
)} {uploading && (
Parsing CSV and importing results...
)}

CSV Example:

{`driverId,position,fastestLap,incidents,startPosition
550e8400-e29b-41d4-a716-446655440001,1,92.456,0,3
550e8400-e29b-41d4-a716-446655440002,2,92.789,1,1
550e8400-e29b-41d4-a716-446655440003,3,93.012,2,2`}
        
); }