import React, { useState } from "react"; import { FlightEditNotNull, Flight } from "../../Types"; import { useNavigate, useParams } from "react-router"; import "./FlightForm.css"; import { editFlight } from "../../Api"; interface Props { flight?: Flight; } export const EditFlight: React.FC = (props) => { const navigate = useNavigate(); let { id } = useParams(); const [error, setError] = useState(null); const [flightData, setFlightData] = useState({ status: "", departure_time: "", arrival_time: "", gate: "" }); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); setError(null); const token = localStorage.getItem("token"); if (!token) { setError("No token!"); return; } let data: any = {} if (flightData.arrival_time != "") { data["arrival_time"] = flightData.arrival_time } if (flightData.departure_time != ""){ data["departure_time"] = flightData.departure_time } if (flightData.status != ""){ data["status"] = flightData.status } if (flightData.gate != ""){ data["gate"] = flightData.gate } if (id == null || id == undefined) return; editFlight(id, data, token) .then((data) => { navigate("/home") }) .catch((error) => { try { setError(JSON.parse(error.response.data)["detail"] as string); } catch {} }); }; return (
{error &&

Error: {error}

}
); };