@@ -8,6 +8,7 @@ import { MenuCategory } from "@prisma/client";
88import { NewProduct , Product } from "@/app/(pages)/(main)/volunteering/menu/product" ;
99import { styled } from "@mui/system" ;
1010import CircularProgress from "@mui/material/CircularProgress" ;
11+ import { DeletionConfirmationDialog } from "@/app/components/input/DeletionConfirmationDialog" ;
1112
1213
1314// Updates a given category.
@@ -66,6 +67,10 @@ export function Category(
6667 let [ isUpdating , setIsUpdating ] = useState < boolean > ( false ) ;
6768
6869
70+ let [ deleteDialogOpen , setDeleteDialogOpen ] = useState < boolean > ( false ) ;
71+ let [ isDeleting , setIsDeleting ] = useState < boolean > ( false ) ;
72+
73+
6974 useEffect ( ( ) => {
7075 // useEffect is always run once at the start.
7176 if ( isFirst ) {
@@ -81,7 +86,7 @@ export function Category(
8186 < Stack >
8287 < Grid container spacing = { 2 } columns = { 10 } >
8388
84- < Grid item xs = { 9 } >
89+ < Grid item xs = { 8 } >
8590 < LargeTextField
8691 type = "text"
8792 value = { categoryName }
@@ -120,6 +125,17 @@ export function Category(
120125 }
121126 </ Button >
122127 </ Grid >
128+
129+ < Grid item xs = { 1 } display = "flex" alignItems = "center" >
130+ < Button
131+ color = "error"
132+ onClick = { ( ) => {
133+ setDeleteDialogOpen ( true ) ;
134+ } }
135+ >
136+ Delete
137+ </ Button >
138+ </ Grid >
123139 </ Grid >
124140
125141
@@ -147,6 +163,21 @@ export function Category(
147163
148164 < NewProduct onUpdate = { props . onUpdate } categoryId = { props . category . id } > </ NewProduct >
149165 </ Grid >
166+
167+ < DeletionConfirmationDialog
168+ open = { deleteDialogOpen }
169+ onClose = { ( ) => setDeleteDialogOpen ( false ) }
170+ onDelete = { ( ) => {
171+ setIsDeleting ( true ) ;
172+ deleteCategory ( props . category . id ) . then ( ( ) => {
173+ props . onUpdate ( ) ;
174+ } ) ;
175+ } }
176+ showSpinner = { isDeleting }
177+ title = "Delete category?"
178+ >
179+ Are you sure you want to delete this category?
180+ </ DeletionConfirmationDialog >
150181 </ Stack >
151182 )
152183}
@@ -187,9 +218,7 @@ export function NewCategory(props: { onUpdate: () => void }) {
187218 setIsCreating ( false ) ;
188219 props . onUpdate ( ) ;
189220 } ) ;
190- }
191-
192- }
221+ } }
193222 > { isCreating ? < CircularProgress /> : < > Create</ > } </ Button >
194223
195224
0 commit comments