From 918a705c4ccb44f7f01c68961dde727a3889155f Mon Sep 17 00:00:00 2001 From: april Date: Fri, 5 Jan 2024 12:16:34 -0600 Subject: [PATCH] Fix time entry and missing data display --- web/app/ui/display/log-item.tsx | 14 ++++++++++--- web/app/ui/form/int-input.tsx | 4 ++-- web/app/util/types.ts | 37 ++++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/web/app/ui/display/log-item.tsx b/web/app/ui/display/log-item.tsx index 479a2c1..7ad8795 100644 --- a/web/app/ui/display/log-item.tsx +++ b/web/app/ui/display/log-item.tsx @@ -1,4 +1,5 @@ import { Card, Group, Stack, Text } from "@mantine/core"; +import { IconX } from "@tabler/icons-react"; export function LogItem({ label, @@ -35,7 +36,10 @@ export function VerticalLogItem({ if (content === null) content = ""; if (decimal > 0) content = Number(content).toFixed(decimal); if (hours) content = Number(content).toFixed(1); - if (time) content = content.split("T")[1]; + if (time) { + const time = content.split("T")[1].split(":"); + content = `${time[0]}:${time[1]}`; + } if (date) content = content.split("T")[0]; return ( @@ -44,8 +48,12 @@ export function VerticalLogItem({ {label} - - {content} + + {content === "" ? : content} diff --git a/web/app/ui/form/int-input.tsx b/web/app/ui/form/int-input.tsx index 28e9eb2..13ab1f6 100644 --- a/web/app/ui/form/int-input.tsx +++ b/web/app/ui/form/int-input.tsx @@ -27,7 +27,7 @@ function IntInput({ onClick={() => form.setFieldValue(field, "")} style={{ display: - ["", null].indexOf(form.getTransformedValues()[field_key]) > -1 + ["", null].indexOf(form.getTransformedValues()[field_key]) === 0 ? "none" : undefined, }} @@ -63,7 +63,7 @@ function ZeroIntInput({ onClick={() => form.setFieldValue(field, 0)} style={{ display: - form.getTransformedValues()[field_key] > 0 ? "none" : undefined, + form.getTransformedValues()[field_key] === 0 ? "none" : undefined, }} /> } diff --git a/web/app/util/types.ts b/web/app/util/types.ts index 3523bfd..0ac358e 100644 --- a/web/app/util/types.ts +++ b/web/app/util/types.ts @@ -57,10 +57,10 @@ type FlightFormSchema = FlightBaseSchema & { type FlightCreateSchema = FlightBaseSchema & { date: string; - time_start: dayjs.Dayjs; - time_off: dayjs.Dayjs; - time_down: dayjs.Dayjs; - time_stop: dayjs.Dayjs; + time_start: string; + time_off: string; + time_down: string; + time_stop: string; }; type FlightDisplaySchema = FlightBaseSchema & { @@ -89,6 +89,7 @@ type FlightConciseSchema = { }; const flightCreateHelper = (values: FlightFormSchema): FlightCreateSchema => { + console.log(values.date.utc().startOf("date").toISOString()); return { ...values, date: values.date.utc().startOf("day").toISOString(), @@ -98,20 +99,32 @@ const flightCreateHelper = (values: FlightFormSchema): FlightCreateSchema => { tach_end: Number(values.tach_end), time_start: values.date .utc() - .hour(values.time_start ?? 0 / 100) - .minute(values.time_start ?? 0 % 100), + .hour(Math.floor((values.time_start ?? 0) / 100)) + .minute(Math.floor((values.time_start ?? 0) % 100)) + .second(0) + .millisecond(0) + .toISOString(), time_off: values.date .utc() - .hour(values.time_off ?? 0 / 100) - .minute(values.time_off ?? 0 % 100), + .hour(Math.floor((values.time_off ?? 0) / 100)) + .minute(Math.floor((values.time_off ?? 0) % 100)) + .second(0) + .millisecond(0) + .toISOString(), time_down: values.date .utc() - .hour(values.time_down ?? 0 / 100) - .minute(values.time_down ?? 0 % 100), + .hour(Math.floor((values.time_down ?? 0) / 100)) + .minute(Math.floor((values.time_down ?? 0) % 100)) + .second(0) + .millisecond(0) + .toISOString(), time_stop: values.date .utc() - .hour(values.time_stop ?? 0 / 100) - .minute(values.time_stop ?? 0 % 100), + .hour(Math.floor((values.time_stop ?? 0) / 100)) + .minute(Math.floor((values.time_stop ?? 0) % 100)) + .second(0) + .millisecond(0) + .toISOString(), }; };