import SectionContainer from '../../components/SectionContainer.jsx'; import { useState } from 'react'; import { DataGrid } from '@mui/x-data-grid'; import { Typography, Button, Dialog, DialogTitle, DialogContent, IconButton, Box } from '@mui/material'; import AddOrEditCategoryForm from './AddOrEditCategoryForm.jsx'; import EditRoundedIcon from '@mui/icons-material/EditRounded'; import DeleteRoundedIcon from '@mui/icons-material/DeleteRounded'; import '../../App.css'; const columnsBase = [ { field: 'name', headerName: 'Name', flex: 1 }, { field: 'description', headerName: 'Description', flex: 2 } ]; export default function Categories({ children, maxWidth = 'lg', sx = {} }) { const [rows, setRows] = useState([ { id: 1, name: 'Fabrics', description: 'Textile materials including silk, cotton, and synthetics.' }, { id: 2, name: 'Leather Goods', description: 'Leather-based components for luxury goods.' }, { id: 3, name: 'Metal Accessories', description: 'Buttons, zippers, and hardware in metal.' }, { id: 4, name: 'Embellishments', description: 'Decorative materials such as beads and sequins.' } ]); const [open, setOpen] = useState(false); const [editingCategory, setEditingCategory] = useState(null); const [confirmOpen, setConfirmOpen] = useState(false); const [rowToDelete, setRowToDelete] = useState(null); const handleAddOrEditCategory = (category) => { if (editingCategory) { setRows(rows.map((row) => (row.id === editingCategory.id ? { ...editingCategory, ...category } : row))); } else { const id = rows.length + 1; setRows([...rows, { id, ...category }]); } setOpen(false); setEditingCategory(null); }; const handleEditClick = (params) => { setEditingCategory(params.row); 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: '', width: 130, renderCell: (params) => ( handleEditClick(params)} > handleDeleteClick(params.row)} > ) } ]; return ( Categories { setOpen(false); setEditingCategory(null); }} fullWidth> {editingCategory ? 'Edit Category' : 'Add Category'} { setOpen(false); setEditingCategory(null); }} /> setConfirmOpen(false)}> Confirm Delete Are you sure you want to delete {rowToDelete?.name}? ({ top: 8, bottom: 8 })} /> ); }