diff --git a/web/app/root.tsx b/web/app/root.tsx index ebe2348..ad40614 100644 --- a/web/app/root.tsx +++ b/web/app/root.tsx @@ -1,4 +1,5 @@ import "@mantine/core/styles.css"; +import "@mantine/dates/styles.css"; import { cssBundleHref } from "@remix-run/css-bundle"; import type { LinksFunction } from "@remix-run/node"; diff --git a/web/app/routes/logbook.flights.new/route.tsx b/web/app/routes/logbook.flights.new/route.tsx new file mode 100644 index 0000000..191db4a --- /dev/null +++ b/web/app/routes/logbook.flights.new/route.tsx @@ -0,0 +1,344 @@ +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 } 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 createFlight = useMutation({ + mutationFn: async (values: FlightFormSchema) => { + const newFlight = flightCreateHelper(values); + const res = await client.post("/flights", newFlight); + navigate(`/logbook/flights/${res.data.id}`); + }, + onError: (error) => { + console.log(error); + }, + }); + + 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 */} + +
+ + + + + +