From 4a116381826efc1084357da13e0b53c0f40dff6f Mon Sep 17 00:00:00 2001 From: karenvicent Date: Wed, 20 Aug 2025 12:51:24 -0400 Subject: [PATCH] refactor create maintenance window page --- .../Components/ConfigSelect/index.jsx | 38 +++ .../hooks/useMaintenanceActions.jsx | 64 +++++ .../hooks/useMaintenanceData.jsx | 74 ++++++ .../Maintenance/CreateMaintenance/index.jsx | 246 +++--------------- 4 files changed, 219 insertions(+), 203 deletions(-) create mode 100644 client/src/Pages/Maintenance/CreateMaintenance/Components/ConfigSelect/index.jsx create mode 100644 client/src/Pages/Maintenance/CreateMaintenance/hooks/useMaintenanceActions.jsx create mode 100644 client/src/Pages/Maintenance/CreateMaintenance/hooks/useMaintenanceData.jsx diff --git a/client/src/Pages/Maintenance/CreateMaintenance/Components/ConfigSelect/index.jsx b/client/src/Pages/Maintenance/CreateMaintenance/Components/ConfigSelect/index.jsx new file mode 100644 index 000000000..1627ef3d5 --- /dev/null +++ b/client/src/Pages/Maintenance/CreateMaintenance/Components/ConfigSelect/index.jsx @@ -0,0 +1,38 @@ +import Select from "../../../../../Components/Inputs/Select"; +import PropTypes from "prop-types"; +const ConfigSelect = ({ configSelection, valueSelect, onChange, ...props }) => { + const getValueById = (config, id) => { + const item = config.find((config) => config._id === id); + return item ? (item.value ? item.value : item.name) : null; + }; + + const getIdByValue = (config, name) => { + const item = config.find((config) => { + if (config.value) { + return config.value === name; + } else { + return config.name === name; + } + }); + return item ? item._id : null; + }; + + return ( + { - handleFormChange( - "repeat", - getValueById(repeatConfig, event.target.value) - ); - }} - items={repeatConfig} + valueSelect={form.repeat} + configSelection={repeatConfig} + onChange={(value) => handleFormChange("repeat", value)} /> @@ -437,7 +280,7 @@ const CreateMaintenance = () => { }} sx={{}} onChange={(newDate) => { - handleTimeChange("startDate", newDate); + handleFormChange("startDate", newDate); }} error={errors["startDate"]} /> @@ -453,7 +296,7 @@ const CreateMaintenance = () => { > {t("startTime")} - {t("timeZoneInfo")} + {t("timeZoneInfo")} @@ -462,7 +305,7 @@ const CreateMaintenance = () => { label={t("startTime")} value={form.startTime} onChange={(newTime) => { - handleTimeChange("startTime", newTime); + handleFormChange("startTime", newTime); }} slotProps={{ nextIconButton: { sx: { ml: theme.spacing(2) } }, @@ -508,16 +351,11 @@ const CreateMaintenance = () => { error={errors["duration"] ? true : false} helperText={errors["duration"]} /> -