Fix validation and spacing in new flight form

This commit is contained in:
april 2024-01-15 12:54:42 -06:00
parent 29c6c49b3e
commit 325730a9da
2 changed files with 17 additions and 0 deletions

View File

@ -60,6 +60,11 @@ export default function FlightForm({
cancelFunc?: () => void; cancelFunc?: () => void;
autofillHobbs?: boolean; autofillHobbs?: boolean;
}) { }) {
const validate_time = (value) => {
if (value > 2359) return "Time must be between 0000 and 2359";
if (value % 100 > 59) return "Minutes must not exceed 59";
};
const form = useForm<FlightFormSchema>({ const form = useForm<FlightFormSchema>({
initialValues: initialValues ?? { initialValues: initialValues ?? {
date: dayjs(), date: dayjs(),
@ -106,6 +111,14 @@ export default function FlightForm({
images: [], images: [],
}, },
validate: {
aircraft: (value) =>
value?.length ?? 0 > 0 ? null : "Please select an aircraft",
time_start: (value) => validate_time(value),
time_off: (value) => validate_time(value),
time_down: (value) => validate_time(value),
time_stop: (value) => validate_time(value),
},
}); });
const [aircraftOpened, { open: openAircraft, close: closeAircraft }] = const [aircraftOpened, { open: openAircraft, close: closeAircraft }] =
@ -498,6 +511,7 @@ export default function FlightForm({
/> />
<ImageUpload <ImageUpload
form={form} form={form}
mt="md"
field="images" field="images"
label="Images" label="Images"
placeholder="Upload Images" placeholder="Upload Images"

View File

@ -9,6 +9,7 @@ export default function ImageUpload({
field, field,
label = "", label = "",
placeholder = "", placeholder = "",
mt = "",
}: { }: {
form: UseFormReturnType< form: UseFormReturnType<
FlightFormSchema, FlightFormSchema,
@ -17,6 +18,7 @@ export default function ImageUpload({
field: string; field: string;
label?: string; label?: string;
placeholder?: string; placeholder?: string;
mt?: string;
}) { }) {
const ValueComponent: FileInputProps["valueComponent"] = ({ value }) => { const ValueComponent: FileInputProps["valueComponent"] = ({ value }) => {
if (value === null) { if (value === null) {
@ -41,6 +43,7 @@ export default function ImageUpload({
label={label} label={label}
placeholder={placeholder} placeholder={placeholder}
multiple multiple
mt={mt}
accept="image/*" accept="image/*"
valueComponent={ValueComponent} valueComponent={ValueComponent}
rightSectionPointerEvents="none" rightSectionPointerEvents="none"