diff --git a/src/private/Admin.jsx b/src/private/Admin.jsx index beeb516..26fb49b 100644 --- a/src/private/Admin.jsx +++ b/src/private/Admin.jsx @@ -5,6 +5,7 @@ import { DataGrid } from '@mui/x-data-grid'; import { Typography, Button, Dialog, DialogTitle, DialogContent, IconButton, Box } from '@mui/material'; import AddOrEditProductForm from './AddOrEditProductForm.jsx'; import EditIcon from '@mui/icons-material/Edit'; +import DeleteIcon from '@mui/icons-material/Delete'; const columnsBase = [ { field: 'id', headerName: 'ID', width: 70 }, @@ -28,6 +29,9 @@ export default function Admin({ children, maxWidth = 'lg', sx = {} }) { const [open, setOpen] = useState(false); const [editingProduct, setEditingProduct] = useState(null); + const [confirmOpen, setConfirmOpen] = useState(false); + const [rowToDelete, setRowToDelete] = useState(null); + const handleAddOrEditProduct = (product) => { if (editingProduct) { // Update existing @@ -46,16 +50,32 @@ export default function Admin({ children, maxWidth = 'lg', sx = {} }) { setOpen(true); }; + const handleDeleteClick = (row) => { + setRowToDelete(row); + setConfirmOpen(true); + }; + + const confirmDelete = () => { + setRows(rows.filter((row) => row.id !== rowToDelete.id)); + setRowToDelete(null); + setConfirmOpen(false); + }; + const columns = [ ...columnsBase, { field: 'actions', headerName: 'Actions', - width: 100, + width: 130, renderCell: (params) => ( - handleEditClick(params)}> - - + + handleEditClick(params)}> + + + handleDeleteClick(params.row)}> + + + ) } ]; @@ -73,6 +93,20 @@ export default function Admin({ children, maxWidth = 'lg', sx = {} }) { + setConfirmOpen(false)}> + Confirm Delete + + + Are you sure you want to delete{' '} + {rowToDelete?.name}? + + + + + + + +