From 0a5067ef46748ca9a00db82f47d9b4306462751c Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 4 Feb 2026 22:10:52 +0000 Subject: [PATCH] grab monitors --- .../src/Components/v2/inputs/TimePicker.tsx | 61 ++++++++++ client/src/Components/v2/inputs/index.tsx | 1 + client/src/Pages/Maintenance/create/index.tsx | 115 +++++++++++++++++- 3 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 client/src/Components/v2/inputs/TimePicker.tsx diff --git a/client/src/Components/v2/inputs/TimePicker.tsx b/client/src/Components/v2/inputs/TimePicker.tsx new file mode 100644 index 000000000..251332fe1 --- /dev/null +++ b/client/src/Components/v2/inputs/TimePicker.tsx @@ -0,0 +1,61 @@ +import { MobileTimePicker } from "@mui/x-date-pickers/MobileTimePicker"; +import type { MobileTimePickerProps } from "@mui/x-date-pickers/MobileTimePicker"; +import type { Dayjs } from "dayjs"; +import { useTheme } from "@mui/material/styles"; +import Stack from "@mui/material/Stack"; +import { FieldLabel } from "./FieldLabel"; +import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; +import { LocalizationProvider } from "@mui/x-date-pickers"; + +interface TimePickerComponentProps extends Omit, "label"> { + fieldLabel?: string; + required?: boolean; +} + +export const TimePickerComponent = ({ + fieldLabel, + required, + ...props +}: TimePickerComponentProps) => { + const theme = useTheme(); + + const picker = ( + + + + ); + + if (fieldLabel) { + return ( + + {fieldLabel} + {picker} + + ); + } + + return picker; +}; diff --git a/client/src/Components/v2/inputs/index.tsx b/client/src/Components/v2/inputs/index.tsx index 6cb40aade..25d9febe3 100644 --- a/client/src/Components/v2/inputs/index.tsx +++ b/client/src/Components/v2/inputs/index.tsx @@ -15,3 +15,4 @@ export * from "./Slider"; export * from "./ImageUpload"; export * from "./ColorPicker"; export { DatePickerComponent as DatePicker } from "./DatePicker"; +export { TimePickerComponent as TimePicker } from "./TimePicker"; diff --git a/client/src/Pages/Maintenance/create/index.tsx b/client/src/Pages/Maintenance/create/index.tsx index 521832ddc..a15338436 100644 --- a/client/src/Pages/Maintenance/create/index.tsx +++ b/client/src/Pages/Maintenance/create/index.tsx @@ -2,17 +2,24 @@ import Stack from "@mui/material/Stack"; import MenuItem from "@mui/material/MenuItem"; import Typography from "@mui/material/Typography"; import { BasePage, ConfigBox } from "@/Components/v2/design-elements"; -import { TextField, Select, DatePicker } from "@/Components/v2/inputs"; +import { + TextField, + Select, + DatePicker, + TimePicker, + Button, +} from "@/Components/v2/inputs"; import { useTheme } from "@mui/material"; import { useTranslation } from "react-i18next"; import dayjs from "dayjs"; import type { MaintenanceWindow } from "@/Types/MaintenanceWindow"; import type { MaintenanceWindowFormData } from "@/Validation/maintenanceWindow"; -import { repeatOptions } from "@/Validation/maintenanceWindow"; +import { repeatOptions, durationUnitOptions } from "@/Validation/maintenanceWindow"; import { useMaintenanceWindowForm } from "@/Hooks/useMaintenanceWindowForm"; import { useGet } from "@/Hooks/UseApi"; import { useParams } from "react-router-dom"; +import type { Monitor } from "@/Types/Monitor"; import { useForm, Controller } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js"; @@ -26,6 +33,8 @@ const CreateMaintenanceWindowPage = () => { isEditMode ? `/maintenance-window/${maintenanceWindowId}` : null ); + const { data: monitors } = useGet("/monitors/team"); + const { schema, defaults } = useMaintenanceWindowForm({ data: existingMaintenanceWindow, }); @@ -35,10 +44,21 @@ const CreateMaintenanceWindowPage = () => { defaultValues: defaults, }); - const { control } = form; + const { control, handleSubmit } = form; + + const onSubmit = (data: MaintenanceWindowFormData) => { + console.log("Form submitted with data:", data); + }; + + const onError = (errors: any) => { + console.log("Form errors:", errors); + }; return ( - + { } /> + + ( + { + field.onChange(time ? time.format("HH:mm") : ""); + }} + /> + )} + /> + + ( + { + const val = e.target.value; + field.onChange(val === "" ? 0 : Number(val)); + }} + error={!!fieldState.error} + helperText={fieldState.error?.message ?? ""} + sx={{ width: 120 }} + /> + )} + /> + ( + + )} + /> + + + } + /> + + + ); };