11import { MenuProduct } from "@prisma/client" ;
22import { useEffect , useState } from "react" ;
3- import {
4- Button ,
5- Checkbox ,
6- Dialog ,
7- DialogActions ,
8- DialogContent ,
9- DialogContentText ,
10- DialogTitle ,
11- FormControlLabel ,
12- Grid ,
13- TextField ,
14- Tooltip
15- } from "@mui/material" ;
3+ import { Button , Checkbox , FormControlLabel , Grid , TextField , Tooltip } from "@mui/material" ;
164import { MenuProductCreate } from "@/app/api/v2/escape/menu/products/route" ;
175import CircularProgress from "@mui/material/CircularProgress" ;
6+ import { DeletionConfirmationDialog } from "@/app/components/input/DeletionConfirmationDialog" ;
187
198function updateProduct ( product : MenuProduct , newAttributes : Partial < MenuProduct > ) : Promise < Response > {
209 return fetch ( "/api/v2/escape/menu/products" , {
@@ -109,18 +98,23 @@ export function Product(props: { product: MenuProduct, onUpdate: () => void }) {
10998 Delete
11099 </ Button >
111100
112- < DeletionConfirmationDialog open = { deleteDialogOpen } onClose = { ( ) => setDeleteDialogOpen ( false ) }
113- onDelete = { ( ) => {
114- setIsDeleting ( true ) ;
115- deleteProduct ( props . product . id ) . then ( ( ) => {
116- setIsDeleting ( false ) ;
117- setDeleteDialogOpen ( false ) ;
118-
119- props . onUpdate ( ) ;
120- } ) ;
121- } }
122- isDeleting = { isDeleting }
123- />
101+ < DeletionConfirmationDialog
102+ open = { deleteDialogOpen }
103+ onClose = { ( ) => setDeleteDialogOpen ( false ) }
104+ onDelete = { ( ) => {
105+ setIsDeleting ( true ) ;
106+ deleteProduct ( props . product . id ) . then ( ( ) => {
107+ setIsDeleting ( false ) ;
108+ setDeleteDialogOpen ( false ) ;
109+
110+ props . onUpdate ( ) ;
111+ } ) ;
112+ } }
113+ showSpinner = { isDeleting }
114+ title = { "Delete product?" }
115+ >
116+ Are you sure you want to delete this product?
117+ </ DeletionConfirmationDialog >
124118 </ Grid >
125119 </ >
126120 )
@@ -354,36 +348,4 @@ export function NewProduct(props: { onUpdate: () => void, categoryId: number | n
354348 </ Grid >
355349 </ >
356350 ) ;
357- }
358-
359- // Dialog to confirm deletion of a product.
360- function DeletionConfirmationDialog ( props : {
361- open : boolean ,
362- onClose : ( ) => void , // called when "Cancel" is clicked, or the dialog is closed in any other way.
363- onDelete : ( ) => void , // called when "Delete" is clicked.
364- isDeleting : boolean // when true, shows a spinner instead of "Delete" in the button.
365- } ) {
366- return (
367- < Dialog
368- open = { props . open }
369- onClose = { props . onClose }
370- aria-labelledby = "alert-dialog-title"
371- aria-describedby = "alert-dialog-description"
372- >
373- < DialogTitle id = "alert-dialog-title" >
374- Delete product?
375- </ DialogTitle >
376- < DialogContent >
377- < DialogContentText id = "alert-dialog-description" >
378- Are you sure you want to delete the product?
379- </ DialogContentText >
380- </ DialogContent >
381- < DialogActions >
382- < Button onClick = { props . onClose } > Cancel</ Button >
383- < Button onClick = { props . onDelete } color = "error" >
384- { props . isDeleting ? < CircularProgress /> : < > Delete</ > }
385- </ Button >
386- </ DialogActions >
387- </ Dialog >
388- ) ;
389351}
0 commit comments