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 { Card, Group, Stack, Text } from "@mantine/core";
import { IconX } from "@tabler/icons-react";
export function LogItem({ export function LogItem({
label, label,
@ -35,7 +36,10 @@ export function VerticalLogItem({
if (content === null) content = ""; if (content === null) content = "";
if (decimal > 0) content = Number(content).toFixed(decimal); if (decimal > 0) content = Number(content).toFixed(decimal);
if (hours) content = Number(content).toFixed(1); 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]; if (date) content = content.split("T")[0];
return ( return (
@ -44,8 +48,12 @@ export function VerticalLogItem({
<Text c="dimmed" style={{ textalign: "center" }}> <Text c="dimmed" style={{ textalign: "center" }}>
{label} {label}
</Text> </Text>
<Text size="lg" style={{ textalign: "center" }}> <Text
{content} size="lg"
style={{ textalign: "center" }}
c={content === "" ? "dimmed" : ""}
>
{content === "" ? <IconX /> : content}
</Text> </Text>
</Stack> </Stack>
</Card> </Card>

View File

@ -27,7 +27,7 @@ function IntInput({
onClick={() => form.setFieldValue(field, "")} onClick={() => form.setFieldValue(field, "")}
style={{ style={{
display: display:
["", null].indexOf(form.getTransformedValues()[field_key]) > -1 ["", null].indexOf(form.getTransformedValues()[field_key]) === 0
? "none" ? "none"
: undefined, : undefined,
}} }}
@ -63,7 +63,7 @@ function ZeroIntInput({
onClick={() => form.setFieldValue(field, 0)} onClick={() => form.setFieldValue(field, 0)}
style={{ style={{
display: 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 & { type FlightCreateSchema = FlightBaseSchema & {
date: string; date: string;
time_start: dayjs.Dayjs; time_start: string;
time_off: dayjs.Dayjs; time_off: string;
time_down: dayjs.Dayjs; time_down: string;
time_stop: dayjs.Dayjs; time_stop: string;
}; };
type FlightDisplaySchema = FlightBaseSchema & { type FlightDisplaySchema = FlightBaseSchema & {
@ -89,6 +89,7 @@ type FlightConciseSchema = {
}; };
const flightCreateHelper = (values: FlightFormSchema): FlightCreateSchema => { const flightCreateHelper = (values: FlightFormSchema): FlightCreateSchema => {
console.log(values.date.utc().startOf("date").toISOString());
return { return {
...values, ...values,
date: values.date.utc().startOf("day").toISOString(), date: values.date.utc().startOf("day").toISOString(),
@ -98,20 +99,32 @@ const flightCreateHelper = (values: FlightFormSchema): FlightCreateSchema => {
tach_end: Number(values.tach_end), tach_end: Number(values.tach_end),
time_start: values.date time_start: values.date
.utc() .utc()
.hour(values.time_start ?? 0 / 100) .hour(Math.floor((values.time_start ?? 0) / 100))
.minute(values.time_start ?? 0 % 100), .minute(Math.floor((values.time_start ?? 0) % 100))
.second(0)
.millisecond(0)
.toISOString(),
time_off: values.date time_off: values.date
.utc() .utc()
.hour(values.time_off ?? 0 / 100) .hour(Math.floor((values.time_off ?? 0) / 100))
.minute(values.time_off ?? 0 % 100), .minute(Math.floor((values.time_off ?? 0) % 100))
.second(0)
.millisecond(0)
.toISOString(),
time_down: values.date time_down: values.date
.utc() .utc()
.hour(values.time_down ?? 0 / 100) .hour(Math.floor((values.time_down ?? 0) / 100))
.minute(values.time_down ?? 0 % 100), .minute(Math.floor((values.time_down ?? 0) % 100))
.second(0)
.millisecond(0)
.toISOString(),
time_stop: values.date time_stop: values.date
.utc() .utc()
.hour(values.time_stop ?? 0 / 100) .hour(Math.floor((values.time_stop ?? 0) / 100))
.minute(values.time_stop ?? 0 % 100), .minute(Math.floor((values.time_stop ?? 0) % 100))
.second(0)
.millisecond(0)
.toISOString(),
}; };
}; };