chore: add and Edit Products
This commit is contained in:
		| @@ -4,6 +4,8 @@ import { Box, Button, TextField, MenuItem, Grid } from '@mui/material'; | |||||||
| import FurnitureVariantApi from '../../api/furnitureVariantApi'; | import FurnitureVariantApi from '../../api/furnitureVariantApi'; | ||||||
| import { useAuth } from '../../context/AuthContext'; | import { useAuth } from '../../context/AuthContext'; | ||||||
|  |  | ||||||
|  | const DEFAULT_MODEL_ID = '8a23117b-acaf-4d87-b64f-a98e9b414796'; | ||||||
|  |  | ||||||
| export default function AddOrEditFurnitureVariantForm({ initialData, onAdd, onCancel }) { | export default function AddOrEditFurnitureVariantForm({ initialData, onAdd, onCancel }) { | ||||||
|   const { user } = useAuth(); |   const { user } = useAuth(); | ||||||
|   const token = user?.thalosToken || localStorage.getItem('thalosToken'); |   const token = user?.thalosToken || localStorage.getItem('thalosToken'); | ||||||
| @@ -11,6 +13,7 @@ export default function AddOrEditFurnitureVariantForm({ initialData, onAdd, onCa | |||||||
|  |  | ||||||
|   const [form, setForm] = useState({ |   const [form, setForm] = useState({ | ||||||
|     _Id: '', |     _Id: '', | ||||||
|  |     id: '', | ||||||
|     modelId: '', |     modelId: '', | ||||||
|     name: '', |     name: '', | ||||||
|     color: '', |     color: '', | ||||||
| @@ -28,6 +31,7 @@ export default function AddOrEditFurnitureVariantForm({ initialData, onAdd, onCa | |||||||
|     if (initialData) { |     if (initialData) { | ||||||
|       setForm({ |       setForm({ | ||||||
|         _Id: initialData._id || initialData._Id || '', |         _Id: initialData._id || initialData._Id || '', | ||||||
|  |         id: initialData.id || initialData.Id || initialData._id || initialData._Id || '', | ||||||
|         modelId: initialData.modelId ?? '', |         modelId: initialData.modelId ?? '', | ||||||
|         name: initialData.name ?? '', |         name: initialData.name ?? '', | ||||||
|         color: initialData.color ?? '', |         color: initialData.color ?? '', | ||||||
| @@ -47,7 +51,8 @@ export default function AddOrEditFurnitureVariantForm({ initialData, onAdd, onCa | |||||||
|     } else { |     } else { | ||||||
|       setForm({ |       setForm({ | ||||||
|         _Id: '', |         _Id: '', | ||||||
|         modelId: '', |         id: '', | ||||||
|  |         modelId: DEFAULT_MODEL_ID, | ||||||
|         name: '', |         name: '', | ||||||
|         color: '', |         color: '', | ||||||
|         line: '', |         line: '', | ||||||
| @@ -70,6 +75,7 @@ export default function AddOrEditFurnitureVariantForm({ initialData, onAdd, onCa | |||||||
|       if (form._Id) { |       if (form._Id) { | ||||||
|         // UPDATE |         // UPDATE | ||||||
|         const payload = { |         const payload = { | ||||||
|  |           Id: form.id || form._Id, // backend requires Id | ||||||
|           _Id: form._Id, |           _Id: form._Id, | ||||||
|           modelId: form.modelId, |           modelId: form.modelId, | ||||||
|           name: form.name, |           name: form.name, | ||||||
| @@ -119,8 +125,37 @@ export default function AddOrEditFurnitureVariantForm({ initialData, onAdd, onCa | |||||||
|     <Box sx={{ py: 2 }}> |     <Box sx={{ py: 2 }}> | ||||||
|       <Grid container spacing={2}> |       <Grid container spacing={2}> | ||||||
|         <Grid item xs={12} md={6}> |         <Grid item xs={12} md={6}> | ||||||
|           <TextField fullWidth label="Model Id" value={form.modelId} onChange={(e) => setVal('modelId', e.target.value)} /> |           <TextField | ||||||
|  |             fullWidth | ||||||
|  |             label="Model Id" | ||||||
|  |             value={form.modelId} | ||||||
|  |             onChange={(e) => setVal('modelId', e.target.value)} | ||||||
|  |             disabled={!initialData} | ||||||
|  |             helperText={!initialData ? 'Preset for new variant' : ''} | ||||||
|  |           /> | ||||||
|         </Grid> |         </Grid> | ||||||
|  |         {form.id && ( | ||||||
|  |           <Grid item xs={12} md={6}> | ||||||
|  |             <TextField | ||||||
|  |               fullWidth | ||||||
|  |               label="Id" | ||||||
|  |               value={form.id} | ||||||
|  |               disabled | ||||||
|  |               helperText="Record identifier (read-only)" | ||||||
|  |             /> | ||||||
|  |           </Grid> | ||||||
|  |         )} | ||||||
|  |         {form._Id && ( | ||||||
|  |           <Grid item xs={12} md={6}> | ||||||
|  |             <TextField | ||||||
|  |               fullWidth | ||||||
|  |               label="_Id" | ||||||
|  |               value={form._Id} | ||||||
|  |               disabled | ||||||
|  |               helperText="Mongo identifier (read-only)" | ||||||
|  |             /> | ||||||
|  |           </Grid> | ||||||
|  |         )} | ||||||
|         <Grid item xs={12} md={6}> |         <Grid item xs={12} md={6}> | ||||||
|           <TextField fullWidth label="Name" value={form.name} onChange={(e) => setVal('name', e.target.value)} /> |           <TextField fullWidth label="Name" value={form.name} onChange={(e) => setVal('name', e.target.value)} /> | ||||||
|         </Grid> |         </Grid> | ||||||
|   | |||||||
| @@ -99,6 +99,7 @@ export default function FurnitureVariantManagement() { | |||||||
|     const r = params.row; |     const r = params.row; | ||||||
|     const normalized = { |     const normalized = { | ||||||
|       _id: r._id || r._Id || '', |       _id: r._id || r._Id || '', | ||||||
|  |       _Id: r._id || r._Id || '', | ||||||
|       id: r.id || r.Id || '', |       id: r.id || r.Id || '', | ||||||
|       modelId: r.modelId ?? '', |       modelId: r.modelId ?? '', | ||||||
|       name: r.name ?? '', |       name: r.name ?? '', | ||||||
| @@ -127,7 +128,7 @@ export default function FurnitureVariantManagement() { | |||||||
|  |  | ||||||
|   const handleConfirmDelete = async () => { |   const handleConfirmDelete = async () => { | ||||||
|     try { |     try { | ||||||
|       if (!apiRef.current || !rowToDelete?._id) throw new Error('Missing API or id'); |       if (!apiRef.current || !(rowToDelete?._id || rowToDelete?._Id)) throw new Error('Missing API or id'); | ||||||
|       // If your inventory BFF uses soft delete via Update (status=Inactive), do this: |       // If your inventory BFF uses soft delete via Update (status=Inactive), do this: | ||||||
|       const payload = { |       const payload = { | ||||||
|         _Id: rowToDelete._id || rowToDelete._Id, |         _Id: rowToDelete._id || rowToDelete._Id, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Rodolfo Ruiz
					Rodolfo Ruiz