import React, { useState, useEffect } from 'react'; import axios from 'axios'; interface JobFormProps { onJobSubmitted: (jobId: string) => void; selectedLat?: string; selectedLon?: string; } const API_ENDPOINT = 'https://api.portfolio.techarvest.co.zw'; const JobForm: React.FC = ({ onJobSubmitted, selectedLat, selectedLon }) => { const [lat, setLat] = useState('-17.8'); const [lon, setLon] = useState('31.0'); const [radius, setRadius] = useState(2000); const [year, setYear] = useState('2022'); const [loading, setLoading] = useState(false); useEffect(() => { if (selectedLat) setLat(selectedLat); if (selectedLon) setLon(selectedLon); }, [selectedLat, selectedLon]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); const token = localStorage.getItem('token'); if (!token) { alert('Authentication required.'); return; } setLoading(true); try { const response = await axios.post(`${API_ENDPOINT}/jobs`, { lat: parseFloat(lat), lon: parseFloat(lon), radius_km: radius / 1000, year: year, model_name: 'Ensemble' }, { headers: { 'Authorization': `Bearer ${token}` } }); onJobSubmitted(response.data.job_id); } catch (err) { console.error('Failed to submit job:', err); alert('Failed to submit job. Check console.'); } finally { setLoading(false); } }; return (

Submit New Job

setLat(e.target.value)} style={{ width: '100%', padding: '8px', border: '1px solid #ddd', borderRadius: '4px', boxSizing: 'border-box' }} />
setLon(e.target.value)} style={{ width: '100%', padding: '8px', border: '1px solid #ddd', borderRadius: '4px', boxSizing: 'border-box' }} />
setRadius(parseInt(e.target.value))} style={{ width: '100%', padding: '8px', border: '1px solid #ddd', borderRadius: '4px', boxSizing: 'border-box' }} />
); }; export default JobForm;