import { VerticalLogItem } from "@/ui/display/log-item";
import ErrorDisplay from "@/ui/error-display";
import { useApi } from "@/util/api";
import {
ActionIcon,
Center,
Container,
Grid,
Group,
Loader,
ScrollArea,
Stack,
Title,
Tooltip,
Text,
Modal,
Button,
} from "@mantine/core";
import { useDisclosure } from "@mantine/hooks";
import { useNavigate, useParams } from "@remix-run/react";
import { IconPencil, IconTrash } from "@tabler/icons-react";
import { useMutation, useQuery } from "@tanstack/react-query";
export default function Flight() {
const params = useParams();
const client = useApi();
const navigate = useNavigate();
const flight = useQuery({
queryKey: [params.id],
queryFn: async () =>
await client.get(`/flights/${params.id}`).then((res) => res.data),
});
const [deleteOpened, { open: openDelete, close: closeDelete }] =
useDisclosure(false);
const deleteFlight = useMutation({
mutationFn: async () =>
await client.delete(`/flights/${params.id}`).then((res) => res.data),
onSuccess: () => {
navigate("/logbook/flights");
},
});
const log = flight.data;
return (
<>
Are you sure you want to delete this flight? This action cannot be
undone.
{deleteFlight.isError ? (
{deleteFlight.error.message}
) : null}
{flight.isError ? (
) : flight.isPending ? (
) : flight.data ? (
<>
Flight Log
{log.waypoint_from || log.waypoint_to ? (
<>
>
) : null}
{log.route ? (
<>
>
) : null}
{log.hobbs_start || log.hobbs_end ? (
<>
>
) : null}
{log.tach_start || log.tach_end ? (
<>
>
) : null}
{log.time_start || log.time_off ? (
<>
>
) : null}
{log.time_down || log.time_stop ? (
<>
>
) : null}
{log.time_xc && log.dist_xc ? (
<>
>
) : null}
{log.time_instrument ||
log.time_sim_instrument ||
log.holds_instrument ? (
<>
>
) : null}
>
) : (
)}
>
);
}