feat: add cancel button
This commit is contained in:
		| @@ -1,7 +1,7 @@ | |||||||
| import React, { useState, useEffect } from 'react'; | import React, { useState, useEffect } from 'react'; | ||||||
| import { Box, Button, TextField, Grid } from '@mui/material'; | import { Box, Button, TextField, Grid } from '@mui/material'; | ||||||
|  |  | ||||||
| export default function AddOrEditProductForm({ onAdd, initialData }) { | export default function AddOrEditProductForm({ onAdd, initialData, onCancel }) { | ||||||
|   const [product, setProduct] = useState({ |   const [product, setProduct] = useState({ | ||||||
|     name: '', |     name: '', | ||||||
|     price: '', |     price: '', | ||||||
| @@ -88,10 +88,12 @@ export default function AddOrEditProductForm({ onAdd, initialData }) { | |||||||
|         onChange={handleChange} |         onChange={handleChange} | ||||||
|         margin="normal" |         margin="normal" | ||||||
|       /> |       /> | ||||||
|       <Box display="flex" justifyContent="flex-end" mt={2}> |      <Box mt={2}> | ||||||
|         <Button variant="contained" onClick={handleSubmit}> |       {/* Fields... */} | ||||||
|           Save |       <Box display="flex" justifyContent="flex-end" gap={1} mt={2}> | ||||||
|         </Button> |         <Button onClick={onCancel}>Cancel</Button> | ||||||
|  |         <Button variant="contained" onClick={handleSubmit}>Save</Button> | ||||||
|  |       </Box> | ||||||
|     </Box> |     </Box> | ||||||
|     </Box> |     </Box> | ||||||
|   ); |   ); | ||||||
|   | |||||||
| @@ -89,7 +89,7 @@ export default function Admin({ children, maxWidth = 'lg', sx = {} }) { | |||||||
|             <Dialog open={open} onClose={() => { setOpen(false); setEditingProduct(null); }} maxWidth="sm" fullWidth> |             <Dialog open={open} onClose={() => { setOpen(false); setEditingProduct(null); }} maxWidth="sm" fullWidth> | ||||||
|                 <DialogTitle>{editingProduct ? 'Edit Product' : 'Add Product'}</DialogTitle> |                 <DialogTitle>{editingProduct ? 'Edit Product' : 'Add Product'}</DialogTitle> | ||||||
|                 <DialogContent> |                 <DialogContent> | ||||||
|                     <AddOrEditProductForm onAdd={handleAddOrEditProduct} initialData={editingProduct} /> |                     <AddOrEditProductForm onAdd={handleAddOrEditProduct} initialData={editingProduct} onCancel={() => { setOpen(false); setEditingProduct(null); }}/> | ||||||
|                 </DialogContent> |                 </DialogContent> | ||||||
|             </Dialog> |             </Dialog> | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Rodolfo Ruiz
					Rodolfo Ruiz