diff --git a/src/models/Product.js b/src/models/Product.js index f29cbe4..c874cd3 100644 --- a/src/models/Product.js +++ b/src/models/Product.js @@ -5,7 +5,7 @@ import ProductPrice from "./ProductPrice"; import { ProviderProduct } from "./ProviderProduct"; export default class Product { - constructor({ id, name, brand = {}, comments, stockCount, images, files = [], providers = [], prices = [], carModels = [], dpi}) { + constructor({ id, name, brand = {}, comments, stockCount, images, files = [], providers = [], prices = [], carModels = [], dpi = ''}) { this.id = id; this.name = name; this.brand = new Brand(brand); diff --git a/src/pages/Products/Forms/RadiatorForm.jsx b/src/pages/Products/Forms/RadiatorForm.jsx index ce110c3..fe091f1 100644 --- a/src/pages/Products/Forms/RadiatorForm.jsx +++ b/src/pages/Products/Forms/RadiatorForm.jsx @@ -53,7 +53,7 @@ const RadiatorFormContainer = ({ setIsFormValid }) => { const { product, handleSetProduct } = useProductDialogContext(); useEffect(() => { - setIsFormValid(product.dpi && product.stockCount); + setIsFormValid(product.stockCount); }, [product.dpi, product.stockCount, setIsFormValid]); const handleChange = (event, field) => { diff --git a/src/pages/Products/ProductViewer/ProductContainer.jsx b/src/pages/Products/ProductViewer/ProductContainer.jsx index c4a4f69..d144bbb 100644 --- a/src/pages/Products/ProductViewer/ProductContainer.jsx +++ b/src/pages/Products/ProductViewer/ProductContainer.jsx @@ -8,6 +8,7 @@ import { useProductsContext } from '../ProductsContext'; import { Screens } from '../ProductsConstants'; import ProductList from './ProductList'; import { ProductCarModel } from '../../../models/ProductCarModel'; +import { deleteProduct } from '../../../services/ProductService'; const ProductContainer = () => { const [productCarModels, setProductCarModels] = useState([]); @@ -19,6 +20,22 @@ const ProductContainer = () => { handleItemSelect(productCarModel.product, Screens.PRODUCTS); } + const handleOnDelete = async (productCarModel) => { + try { + console.log(productCarModel) + let result = await deleteProduct(productCarModel.id); + if (result) { + const products = productCarModels.filter(pcm => pcm.product.id !== productCarModel.id); + setProductCarModels(products); + openSnackbar('Producto eliminado correctamente', 'success'); + } else { + openSnackbar('Error al eliminar el producto', 'error'); + } + } catch (error) { + openSnackbar(`Error al eliminar el producto: ${error.errorMessage}`, 'error'); + } + } + useEffect(() => { setLoading(true); @@ -73,7 +90,7 @@ const ProductContainer = () => { unmountOnExit >