import React, { useState, useEffect } from 'react'; import { Box, Button, TextField, Grid } from '@mui/material'; export default function AddOrEditProductForm({ onAdd, initialData, onCancel }) { const [product, setProduct] = useState({ name: '', price: '', provider: '', stock: '', category: '' }); useEffect(() => { if (initialData) { setProduct(initialData); } else { setProduct({ name: '', price: '', provider: '', stock: '', category: '' }); } }, [initialData]); const handleChange = (e) => { const { name, value } = e.target; setProduct((prev) => ({ ...prev, [name]: name === 'price' || name === 'stock' ? Number(value) : value })); }; const handleSubmit = () => { if (onAdd) { onAdd(product); } }; return ( {/* Fields... */} ); }