Fix time entry and missing data display

This commit is contained in:
april 2024-01-05 12:16:34 -06:00
parent ed490803cb
commit 918a705c4c
3 changed files with 38 additions and 17 deletions

View File

@ -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({
<Text c="dimmed" style={{ textalign: "center" }}>
{label}
</Text>
<Text size="lg" style={{ textalign: "center" }}>
{content}
<Text
size="lg"
style={{ textalign: "center" }}
c={content === "" ? "dimmed" : ""}
>
{content === "" ? <IconX /> : content}
</Text>
</Stack>
</Card>

View File

@ -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,
}}
/>
}

View File

@ -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(),
};
};