import AircraftForm from "@/ui/form/aircraft-form"; import { useApi } from "@/util/api"; import { useAircraft, usePatchFlight } from "@/util/hooks"; import { AircraftFormSchema, AircraftSchema } from "@/util/types"; import { ActionIcon, Group, Tooltip, Text, Select, Modal, Card, Stack, Button, Loader, UnstyledButton, } from "@mantine/core"; import { useDisclosure } from "@mantine/hooks"; import { IconPlus, IconPencil, IconX } from "@tabler/icons-react"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { useState } from "react"; export function AircraftLogItem({ label, content, id = "", field = "", }: { label: string; content: string | null; id?: string; field?: string; }) { const [editValue, setEditValue] = useState(content ?? ""); const [editError, setEditError] = useState(""); const [editOpened, { open: openEdit, close: closeEdit }] = useDisclosure(false); const [aircraftOpened, { open: openAircraft, close: closeAircraft }] = useDisclosure(false); const client = useApi(); const queryClient = useQueryClient(); const addAircraft = useMutation({ mutationFn: async (values: AircraftFormSchema) => { const newAircraft = values; if (newAircraft) { const res = await client.post("/aircraft", newAircraft); return res.data; } throw new Error("Aircraft creation failed"); }, onSuccess: async () => { await queryClient.invalidateQueries({ queryKey: ["aircraft-list"] }); close(); }, }); const getAircraft = useAircraft(); const updateValue = usePatchFlight(id, field, closeEdit); if (content === null) content = ""; const editForm = (