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"]} /> -