Added state to section component, removed console.log from button
This commit is contained in:
1 parent
0272ce8d91
commit
f4832f0324
2 files changed
+24
-4
No files matched your search
@@ -47,7 +47,6 @@ const levelConfig = {
|
|||||||
|
|
||||||
const Button = ({ level, label, disabled, img, sx }) => {
|
const Button = ({ level, label, disabled, img, sx }) => {
|
||||||
const { variant, color } = levelConfig[level];
|
const { variant, color } = levelConfig[level];
|
||||||
console.log(img);
|
|
||||||
return (
|
return (
|
||||||
<MuiButton
|
<MuiButton
|
||||||
variant={variant}
|
variant={variant}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Container,
|
Container,
|
||||||
@@ -23,7 +24,24 @@ import AddIcon from "@mui/icons-material/Add";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const Section = ({ monitors }) => {
|
const Section = ({ monitors }) => {
|
||||||
console.log(monitors);
|
const [monitorStates, setMonitorStates] = useState(
|
||||||
|
monitors.map((monitor) => monitor.isActive)
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("Monitor states updated", monitorStates);
|
||||||
|
// Update DB here
|
||||||
|
}, [monitorStates]);
|
||||||
|
|
||||||
|
const handleMonitor = (monitorIndex) => {
|
||||||
|
setMonitorStates((prevStates) => {
|
||||||
|
const newStates = [...prevStates];
|
||||||
|
newStates[monitorIndex] = !newStates[monitorIndex];
|
||||||
|
|
||||||
|
return newStates;
|
||||||
|
// Need to update DB with new monitor state
|
||||||
|
});
|
||||||
|
};
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -66,7 +84,7 @@ const Section = ({ monitors }) => {
|
|||||||
>
|
>
|
||||||
<Typography>Servers List</Typography>
|
<Typography>Servers List</Typography>
|
||||||
<Button level="primary" label="Add new" />
|
<Button level="primary" label="Add new" />
|
||||||
{monitors.map((monitor) => {
|
{monitors.map((monitor, index) => {
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
key={monitor.id}
|
key={monitor.id}
|
||||||
@@ -85,7 +103,10 @@ const Section = ({ monitors }) => {
|
|||||||
<MenuIcon
|
<MenuIcon
|
||||||
sx={{ color: `${theme.palette.section.borderColor}` }}
|
sx={{ color: `${theme.palette.section.borderColor}` }}
|
||||||
/>
|
/>
|
||||||
<Switch checked={monitor.isActive} />
|
<Switch
|
||||||
|
checked={monitorStates[index]}
|
||||||
|
onChange={() => handleMonitor(index)}
|
||||||
|
/>
|
||||||
<Typography sx={{ flexGrow: 1 }}>{monitor.name}</Typography>
|
<Typography sx={{ flexGrow: 1 }}>{monitor.name}</Typography>
|
||||||
<DeleteOutlineIcon
|
<DeleteOutlineIcon
|
||||||
sx={{ color: `${theme.palette.section.borderColor}` }}
|
sx={{ color: `${theme.palette.section.borderColor}` }}
|
||||||
|
|||||||
Reference in new issue
Block a user