add controls to all inputs
This commit is contained in:
1 parent
fa106d99ed
commit
6ac19000f7
3 files changed
+141
-43
No files matched your search
@@ -15,6 +15,29 @@ import SearchIcon from "../../../assets/icons/search.svg?react";
|
|||||||
* @param {Object} props.sx - Additional styles to apply to the component
|
* @param {Object} props.sx - Additional styles to apply to the component
|
||||||
* @returns {JSX.Element} The rendered Search component
|
* @returns {JSX.Element} The rendered Search component
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const SearchAdornment = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
mr={theme.spacing(4)}
|
||||||
|
height={16}
|
||||||
|
sx={{
|
||||||
|
"& svg": {
|
||||||
|
width: 16,
|
||||||
|
height: 16,
|
||||||
|
"& path": {
|
||||||
|
stroke: theme.palette.text.tertiary,
|
||||||
|
strokeWidth: 1.2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SearchIcon />
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const Search = ({
|
const Search = ({
|
||||||
id,
|
id,
|
||||||
options,
|
options,
|
||||||
@@ -24,11 +47,14 @@ const Search = ({
|
|||||||
handleInputChange,
|
handleInputChange,
|
||||||
handleChange,
|
handleChange,
|
||||||
sx,
|
sx,
|
||||||
|
multiple = false,
|
||||||
|
isAdorned = true,
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
|
multiple={multiple}
|
||||||
id={id}
|
id={id}
|
||||||
inputValue={value}
|
inputValue={value}
|
||||||
onInputChange={(_, newValue) => {
|
onInputChange={(_, newValue) => {
|
||||||
@@ -38,7 +64,7 @@ const Search = ({
|
|||||||
handleChange && handleChange(newValue);
|
handleChange && handleChange(newValue);
|
||||||
}}
|
}}
|
||||||
fullWidth
|
fullWidth
|
||||||
// freeSolo
|
freeSolo
|
||||||
disableClearable
|
disableClearable
|
||||||
options={options}
|
options={options}
|
||||||
getOptionLabel={(option) => option[filteredBy]}
|
getOptionLabel={(option) => option[filteredBy]}
|
||||||
@@ -48,24 +74,7 @@ const Search = ({
|
|||||||
placeholder="Type to search"
|
placeholder="Type to search"
|
||||||
InputProps={{
|
InputProps={{
|
||||||
...params.InputProps,
|
...params.InputProps,
|
||||||
startAdornment: (
|
...(isAdorned && { startAdornment: <SearchAdornment /> }),
|
||||||
<Box
|
|
||||||
mr={theme.spacing(4)}
|
|
||||||
height={16}
|
|
||||||
sx={{
|
|
||||||
"& svg": {
|
|
||||||
width: 16,
|
|
||||||
height: 16,
|
|
||||||
"& path": {
|
|
||||||
stroke: theme.palette.text.tertiary,
|
|
||||||
strokeWidth: 1.2,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<SearchIcon />
|
|
||||||
</Box>
|
|
||||||
),
|
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
"& fieldset": {
|
"& fieldset": {
|
||||||
@@ -141,12 +150,14 @@ const Search = ({
|
|||||||
|
|
||||||
Search.propTypes = {
|
Search.propTypes = {
|
||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
|
multiple: PropTypes.bool,
|
||||||
options: PropTypes.array.isRequired,
|
options: PropTypes.array.isRequired,
|
||||||
filteredBy: PropTypes.string.isRequired,
|
filteredBy: PropTypes.string.isRequired,
|
||||||
secondaryLabel: PropTypes.string,
|
secondaryLabel: PropTypes.string,
|
||||||
value: PropTypes.string.isRequired,
|
value: PropTypes.string.isRequired,
|
||||||
handleInputChange: PropTypes.func.isRequired,
|
handleInputChange: PropTypes.func.isRequired,
|
||||||
handleChange: PropTypes.func,
|
handleChange: PropTypes.func,
|
||||||
|
isAdorned: PropTypes.bool,
|
||||||
sx: PropTypes.object,
|
sx: PropTypes.object,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import "./index.css";
|
|||||||
*
|
*
|
||||||
* <Select
|
* <Select
|
||||||
* id="frequency-id"
|
* id="frequency-id"
|
||||||
|
* name="my-name"
|
||||||
* label="Check frequency"
|
* label="Check frequency"
|
||||||
* placeholder="Select frequency"
|
* placeholder="Select frequency"
|
||||||
* value={value}
|
* value={value}
|
||||||
@@ -51,6 +52,7 @@ const Select = ({
|
|||||||
items,
|
items,
|
||||||
onChange,
|
onChange,
|
||||||
sx,
|
sx,
|
||||||
|
name = "",
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const itemStyles = {
|
const itemStyles = {
|
||||||
@@ -77,6 +79,7 @@ const Select = ({
|
|||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
displayEmpty
|
displayEmpty
|
||||||
|
name={name}
|
||||||
inputProps={{ id: id }}
|
inputProps={{ id: id }}
|
||||||
IconComponent={KeyboardArrowDownIcon}
|
IconComponent={KeyboardArrowDownIcon}
|
||||||
MenuProps={{ disableScrollLock: true }}
|
MenuProps={{ disableScrollLock: true }}
|
||||||
@@ -127,6 +130,7 @@ const Select = ({
|
|||||||
|
|
||||||
Select.propTypes = {
|
Select.propTypes = {
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
|
name: PropTypes.string,
|
||||||
label: PropTypes.string,
|
label: PropTypes.string,
|
||||||
placeholder: PropTypes.string,
|
placeholder: PropTypes.string,
|
||||||
isHidden: PropTypes.bool,
|
isHidden: PropTypes.bool,
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ import { ConfigBox } from "./styled";
|
|||||||
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
|
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
|
||||||
import { LocalizationProvider } from "@mui/x-date-pickers";
|
import { LocalizationProvider } from "@mui/x-date-pickers";
|
||||||
import { DatePicker } from "@mui/x-date-pickers/DatePicker";
|
import { DatePicker } from "@mui/x-date-pickers/DatePicker";
|
||||||
|
import { MobileTimePicker } from "@mui/x-date-pickers/MobileTimePicker";
|
||||||
|
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
import Select from "../../../Components/Inputs/Select";
|
import Select from "../../../Components/Inputs/Select";
|
||||||
import Field from "../../../Components/Inputs/Field";
|
import Field from "../../../Components/Inputs/Field";
|
||||||
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
||||||
@@ -15,9 +19,9 @@ import Search from "../../../Components/Inputs/Search";
|
|||||||
import { networkService } from "../../../main";
|
import { networkService } from "../../../main";
|
||||||
|
|
||||||
const repeatConfig = [
|
const repeatConfig = [
|
||||||
{ _id: 0, name: "Don't repeat" },
|
{ _id: 0, name: "Don't repeat", value: "none" },
|
||||||
{ _id: 1, name: "Repeat daily" },
|
{ _id: 1, name: "Repeat daily", value: "daily" },
|
||||||
{ _id: 2, name: "Repeat weekly" },
|
{ _id: 2, name: "Repeat weekly", value: "weekly" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const durationConfig = [
|
const durationConfig = [
|
||||||
@@ -27,17 +31,33 @@ const durationConfig = [
|
|||||||
{ _id: 3, name: "days" },
|
{ _id: 3, name: "days" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const periodConfig = [
|
const getValueById = (config, id) => {
|
||||||
{ _id: 0, name: "AM" },
|
const item = config.find((config) => config._id === id);
|
||||||
{ _id: 1, name: "PM" },
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
const CreateMaintenance = () => {
|
const CreateMaintenance = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { user, authToken } = useSelector((state) => state.auth);
|
const { user, authToken } = useSelector((state) => state.auth);
|
||||||
const [monitors, setMonitors] = useState([]);
|
const [monitors, setMonitors] = useState([]);
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [selectedMonitor, setSelectedMonitor] = useState(null);
|
const [form, setForm] = useState({
|
||||||
|
repeat: "none",
|
||||||
|
startDate: dayjs().toISOString(),
|
||||||
|
startTime: dayjs().toISOString(),
|
||||||
|
duration: "",
|
||||||
|
durationUnit: "seconds",
|
||||||
|
name: "",
|
||||||
|
monitors: [],
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchMonitors = async () => {
|
const fetchMonitors = async () => {
|
||||||
@@ -56,9 +76,18 @@ const CreateMaintenance = () => {
|
|||||||
setSearch(value);
|
setSearch(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectMonitor = (monitor) => {
|
const handleSelectMonitors = (monitors) => {
|
||||||
setSelectedMonitor(monitor);
|
setForm({ ...form, monitors });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleFormChange = (key, value) => {
|
||||||
|
setForm({ ...form, [key]: value });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTimeChange = (key, newTime) => {
|
||||||
|
setForm({ ...form, [key]: newTime });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="create-maintenance">
|
<Box className="create-maintenance">
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
@@ -106,9 +135,15 @@ const CreateMaintenance = () => {
|
|||||||
>
|
>
|
||||||
<Select
|
<Select
|
||||||
id="maintenance-repeat"
|
id="maintenance-repeat"
|
||||||
|
name="maintenance-repeat"
|
||||||
label="Maintenance Repeat"
|
label="Maintenance Repeat"
|
||||||
value={0}
|
value={getIdByValue(repeatConfig, form.repeat)}
|
||||||
onChange={() => {}}
|
onChange={(event) => {
|
||||||
|
handleFormChange(
|
||||||
|
"repeat",
|
||||||
|
getValueById(repeatConfig, event.target.value)
|
||||||
|
);
|
||||||
|
}}
|
||||||
items={repeatConfig}
|
items={repeatConfig}
|
||||||
/>
|
/>
|
||||||
<Stack gap={theme.spacing(2)} mt={theme.spacing(16)}>
|
<Stack gap={theme.spacing(2)} mt={theme.spacing(16)}>
|
||||||
@@ -156,6 +191,9 @@ const CreateMaintenance = () => {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
sx={{}}
|
sx={{}}
|
||||||
|
onChange={(newDate) => {
|
||||||
|
handleTimeChange("startDate", newDate.toISOString());
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</LocalizationProvider>
|
</LocalizationProvider>
|
||||||
</Stack>
|
</Stack>
|
||||||
@@ -172,12 +210,39 @@ const CreateMaintenance = () => {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<Stack direction="row">
|
<Stack direction="row">
|
||||||
<Select
|
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
||||||
id="maintenance-period"
|
<MobileTimePicker
|
||||||
value={0}
|
id="maintenance-start-time"
|
||||||
items={periodConfig}
|
value={dayjs(form.startTime)}
|
||||||
onChange={() => {}}
|
onChange={(newTime) => {
|
||||||
/>
|
handleTimeChange("startTime", newTime.toISOString());
|
||||||
|
}}
|
||||||
|
slotProps={{
|
||||||
|
nextIconButton: { sx: { ml: theme.spacing(2) } },
|
||||||
|
field: {
|
||||||
|
sx: {
|
||||||
|
width: "fit-content",
|
||||||
|
"& > .MuiOutlinedInput-root": {
|
||||||
|
flexDirection: "row-reverse",
|
||||||
|
},
|
||||||
|
"& input": {
|
||||||
|
height: 34,
|
||||||
|
p: 0,
|
||||||
|
pl: theme.spacing(5),
|
||||||
|
},
|
||||||
|
"& fieldset": {
|
||||||
|
borderColor: theme.palette.border.dark,
|
||||||
|
borderRadius: theme.shape.borderRadius,
|
||||||
|
},
|
||||||
|
"&:not(:has(.Mui-disabled)):not(:has(.Mui-error)) .MuiOutlinedInput-root:not(:has(input:focus)):hover fieldset":
|
||||||
|
{
|
||||||
|
borderColor: theme.palette.border.dark,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</LocalizationProvider>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack direction="row">
|
<Stack direction="row">
|
||||||
@@ -186,12 +251,25 @@ const CreateMaintenance = () => {
|
|||||||
Duration
|
Duration
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<Stack direction="row">
|
<Stack direction="row" spacing={theme.spacing(8)}>
|
||||||
|
<Field
|
||||||
|
type="number"
|
||||||
|
id="maintenance-duration"
|
||||||
|
value={form.duration}
|
||||||
|
onChange={(event) => {
|
||||||
|
handleFormChange("duration", event.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<Select
|
<Select
|
||||||
id="maintenance-unit"
|
id="maintenance-unit"
|
||||||
value={0}
|
value={getIdByValue(durationConfig, form.durationUnit)}
|
||||||
items={durationConfig}
|
items={durationConfig}
|
||||||
onChange={() => {}}
|
onChange={(event) => {
|
||||||
|
handleFormChange(
|
||||||
|
"durationUnit",
|
||||||
|
getValueById(durationConfig, event.target.value)
|
||||||
|
);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
@@ -216,7 +294,10 @@ const CreateMaintenance = () => {
|
|||||||
<Field
|
<Field
|
||||||
id="maintenance-name"
|
id="maintenance-name"
|
||||||
placeholder="Maintenance at __ : __ for ___ minutes"
|
placeholder="Maintenance at __ : __ for ___ minutes"
|
||||||
value=""
|
value={form.name}
|
||||||
|
onChange={(event) => {
|
||||||
|
handleFormChange("name", event.target.value);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
@@ -228,12 +309,14 @@ const CreateMaintenance = () => {
|
|||||||
</Box>
|
</Box>
|
||||||
<Box>
|
<Box>
|
||||||
<Search
|
<Search
|
||||||
|
multiple={true}
|
||||||
|
isAdorned={false}
|
||||||
options={monitors ? monitors : []}
|
options={monitors ? monitors : []}
|
||||||
filteredBy="name"
|
filteredBy="name"
|
||||||
secondaryLabel={"type"}
|
secondaryLabel={"type"}
|
||||||
value={search}
|
value={search}
|
||||||
handleInputChange={handleSearch}
|
handleInputChange={handleSearch}
|
||||||
handleChange={handleSelectMonitor}
|
handleChange={handleSelectMonitors}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
@@ -251,7 +334,7 @@ const CreateMaintenance = () => {
|
|||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => console.log("disabled")}
|
onClick={() => console.log(form)}
|
||||||
disabled={false}
|
disabled={false}
|
||||||
>
|
>
|
||||||
Create maintenance
|
Create maintenance
|
||||||
|
|||||||
Reference in new issue
Block a user