import { Button, CloseButton, Container, Fieldset, Group, NumberInput, ScrollArea, ScrollAreaAutosize, Stack, TextInput, Textarea, Title, } from "@mantine/core"; import { useForm } from "@mantine/form"; import { DatePickerInput } from "@mantine/dates"; import dayjs from "dayjs"; import { IconPencil } from "@tabler/icons-react"; import TimeInput from "@/ui/form/time-input"; import { FlightFormSchema, flightCreateHelper } from "@/util/types"; import { HourInput, ZeroHourInput } from "@/ui/form/hour-input"; import { ZeroIntInput } from "@/ui/form/int-input"; import ListInput from "@/ui/form/list-input"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { client } from "@/util/api"; import { useNavigate } from "@remix-run/react"; export default function NewFlight() { const form = useForm({ initialValues: { date: dayjs(), aircraft: "", waypoint_from: "", waypoint_to: "", route: "", hobbs_start: null, hobbs_end: null, tach_start: null, tach_end: null, time_start: null, time_off: null, time_down: null, time_stop: null, time_total: 0.0, time_pic: 0.0, time_sic: 0.0, time_night: 0.0, time_solo: 0.0, time_xc: 0.0, dist_xc: 0.0, takeoffs_day: 0, landings_day: 0, takeoffs_night: 0, landings_night: 0, time_instrument: 0.0, time_sim_instrument: 0.0, holds_instrument: 0, dual_given: 0.0, dual_recvd: 0.0, time_sim: 0.0, time_ground: 0.0, tags: [], pax: [], crew: [], comments: "", }, }); const navigate = useNavigate(); const queryClient = useQueryClient(); const createFlight = useMutation({ mutationFn: async (values: FlightFormSchema) => { const newFlight = flightCreateHelper(values); const res = await client.post("/flights", newFlight); console.log(res); return res.data; }, onError: (error) => { console.log(error); }, onSuccess: async (data: { id: string }) => { await queryClient.invalidateQueries({ queryKey: ["flights-list"] }); navigate(`/logbook/flights/${data.id}`); }, }); return ( New Flight
createFlight.mutate(values))}> {/* Date and Aircraft */}
{/* Route */}
{/* Times */}
{/* Start/Stop */}
{/* Hours */}
{/* Cross-Country */}
form.setFieldValue("dist_xc", 0)} style={{ display: form.getTransformedValues().dist_xc == 0 ? "none" : undefined, }} /> } {...form.getInputProps("dist_xc")} />
{/* Takeoffs and Landings */}
{/* Instrument */}
{/* Instruction */}
{/* About the Flight */}