import React, { useEffect, useState } from "react"; import { FlightCreate, Flight } from "../../Types"; import { useNavigate } from "react-router"; import "./FlightForm.css"; import { createFlight } from "../../Api"; export const CreateFlight = () => { const navigate = useNavigate(); const [error, setError] = useState(null); const [flight, setFlight] = useState(); const [flightData, setFlightData] = useState({ flight_code: "ABC123", status: "Scheduled", origin: "Frankfurt", destination: "Rome", departure_time: "2023-10-09 10:00 AM", arrival_time: "2023-10-09 12:00 PM", gate: "A1", }); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); setError(null); const token = localStorage.getItem("token"); if (!token) { setError("No token!"); return; } createFlight(flightData, token) .then((data) => { setFlight(data); navigate("/home") }) .catch((error) => { setError(error as string); }); }; return (
); };