diff --git a/src/App.tsx b/src/App.tsx index 36ae6e4..91a8f2e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,6 +3,7 @@ import Sidebar from "./pages/Sidebar"; import TopMenu from "./pages/TopMenu"; import AreaManagement from "./pages/AreaManagement"; import OperatorManagement from "./pages/OperatorManagement"; +import DeviceManagement from "./pages/DeviceManagement"; import Home from "./pages/Home"; // Tipos para las páginas que reciben subPage @@ -22,6 +23,8 @@ export default function App() { return ; // ahora tipado correctamente case "operator": return ; // también + case "device-management": + return ; default: return
Selecciona una opción
; } diff --git a/src/pages/DeviceManagement.tsx b/src/pages/DeviceManagement.tsx new file mode 100644 index 0000000..eaef2de --- /dev/null +++ b/src/pages/DeviceManagement.tsx @@ -0,0 +1,243 @@ +import { useState } from "react"; +import { DataGrid, GridColDef } from "@mui/x-data-grid"; +import { Add, Delete, Refresh, Edit } from "@mui/icons-material"; +import { Button, IconButton, Dialog, DialogTitle, DialogContent, DialogActions, TextField, CircularProgress } from "@mui/material"; + +interface Device { + id: number; + areaName: string; + deviceSn: string; + deviceName: string; + deviceType: string; + deviceStatus: string; + operator: string; + installedTime: string; + communicationTime: string; +} + +interface DeviceManagementProps { + subPage: string; +} + +export default function DeviceManagement({ subPage: _subPage }: DeviceManagementProps) { + const [rows, setRows] = useState([ + { + id: 1, + areaName: "Operaciones", + deviceSn: "DEV001", + deviceName: "Water Meter A1", + deviceType: "Flow Sensor", + deviceStatus: "Installed", + operator: "Juan Pérez", + installedTime: "2024-01-15 10:30:00", + communicationTime: "2024-12-16 14:25:00" + }, + { + id: 2, + areaName: "Calidad", + deviceSn: "DEV002", + deviceName: "Pressure Monitor B2", + deviceType: "Pressure Sensor", + deviceStatus: "Installed", + operator: "María García", + installedTime: "2024-02-20 09:15:00", + communicationTime: "2024-12-16 13:45:00" + }, + { + id: 3, + areaName: "Mantenimiento", + deviceSn: "DEV003", + deviceName: "Temperature Sensor C3", + deviceType: "Temp Sensor", + deviceStatus: "Uninstalled", + operator: "Carlos López", + installedTime: "2024-03-10 11:00:00", + communicationTime: "2024-12-15 16:30:00" + }, + ]); + + const [dialogOpen, setDialogOpen] = useState(false); + const [editMode, setEditMode] = useState(false); + const [currentDevice, setCurrentDevice] = useState({ + id: 0, + areaName: "", + deviceSn: "", + deviceName: "", + deviceType: "", + deviceStatus: "", + operator: "", + installedTime: "", + communicationTime: "", + }); + + const [loading, setLoading] = useState(false); + + const columns: GridColDef[] = [ + { field: "areaName", headerName: "Area Name", width: 150 }, + { field: "deviceSn", headerName: "Device S/N", width: 130 }, + { field: "deviceName", headerName: "Device Name", width: 180 }, + { field: "deviceType", headerName: "Device Type", width: 130 }, + { field: "deviceStatus", headerName: "Device Status", width: 130 }, + { field: "operator", headerName: "Operator", width: 150 }, + { field: "installedTime", headerName: "Installed Time", width: 180 }, + { field: "communicationTime", headerName: "Communication Time", width: 180 }, + { + field: "actions", + headerName: "Actions", + width: 150, + renderCell: (params) => ( +
+ handleEdit(params.row)}> + + + handleDelete(params.row.id)}> + + +
+ ), + }, + ]; + + const handleDelete = (id: number) => { + if (confirm("¿Deseas eliminar este dispositivo?")) { + setRows(rows.filter(row => row.id !== id)); + } + }; + + const handleEdit = (device: Device) => { + setCurrentDevice(device); + setEditMode(true); + setDialogOpen(true); + }; + + const handleAdd = () => { + const newId = rows.length ? Math.max(...rows.map(r => r.id)) + 1 : 1; + setRows([...rows, { ...currentDevice, id: newId }]); + setDialogOpen(false); + resetForm(); + }; + + const handleUpdate = () => { + setRows(rows.map(r => (r.id === currentDevice.id ? currentDevice : r))); + setDialogOpen(false); + resetForm(); + }; + + const resetForm = () => { + setCurrentDevice({ + id: 0, + areaName: "", + deviceSn: "", + deviceName: "", + deviceType: "", + deviceStatus: "", + operator: "", + installedTime: "", + communicationTime: "", + }); + setEditMode(false); + }; + + const handleRefresh = () => { + setLoading(true); + setTimeout(() => { + setRows([...rows]); + setLoading(false); + }, 1000); + }; + + return ( +
+ +
+

Device Management

+
+ + + +
+
+ +
+ +
+ + { setDialogOpen(false); resetForm(); }}> + {editMode ? "Editar Dispositivo" : "Agregar Nuevo Dispositivo"} + + {["areaName","deviceSn","deviceName","deviceType","deviceStatus","operator","installedTime","communicationTime"].map((field) => ( + str.toUpperCase())} + type="text" + value={String(currentDevice[field as keyof Device] || "")} + onChange={(e) => setCurrentDevice({ ...currentDevice, [field]: e.target.value })} + fullWidth + /> + ))} + + + + + + + + +
+ ); +}