@@ -3,7 +3,6 @@ import { ChevronDown } from "lucide-react";
33import { Modal , Form } from "antd" ;
44import {
55 AlertDialog ,
6- AlertDialogAction ,
76 AlertDialogCancel ,
87 AlertDialogContent ,
98 AlertDialogDescription ,
@@ -66,6 +65,7 @@ const CostTrackingSettings: React.FC<CostTrackingSettingsProps> = ({ userID, use
6665 const [ fixedAmountValue , setFixedAmountValue ] = useState < string > ( "" ) ;
6766 const [ models , setModels ] = useState < string [ ] > ( [ ] ) ;
6867 const [ pendingRemoval , setPendingRemoval ] = useState < PendingRemoval | null > ( null ) ;
68+ const [ isRemoving , setIsRemoving ] = useState ( false ) ;
6969 const [ form ] = Form . useForm ( ) ;
7070 const [ marginForm ] = Form . useForm ( ) ;
7171
@@ -131,14 +131,19 @@ const CostTrackingSettings: React.FC<CostTrackingSettingsProps> = ({ userID, use
131131 setPendingRemoval ( { kind : "discount" , provider, displayName : providerDisplayName } ) ;
132132 } ;
133133
134- const handleConfirmRemoval = ( ) => {
134+ const handleConfirmRemoval = async ( ) => {
135135 if ( ! pendingRemoval ) return ;
136- if ( pendingRemoval . kind === "discount" ) {
137- removeProvider ( pendingRemoval . provider ) ;
138- } else {
139- removeMargin ( pendingRemoval . provider ) ;
136+ setIsRemoving ( true ) ;
137+ try {
138+ if ( pendingRemoval . kind === "discount" ) {
139+ await removeProvider ( pendingRemoval . provider ) ;
140+ } else {
141+ await removeMargin ( pendingRemoval . provider ) ;
142+ }
143+ } finally {
144+ setIsRemoving ( false ) ;
145+ setPendingRemoval ( null ) ;
140146 }
141- setPendingRemoval ( null ) ;
142147 } ;
143148
144149 const handleAddMargin = async ( ) => {
@@ -311,7 +316,7 @@ const CostTrackingSettings: React.FC<CostTrackingSettingsProps> = ({ userID, use
311316 </ div >
312317
313318 { pendingRemoval && (
314- < AlertDialog open onOpenChange = { ( open ) => ! open && setPendingRemoval ( null ) } >
319+ < AlertDialog open onOpenChange = { ( open ) => ! open && ! isRemoving && setPendingRemoval ( null ) } >
315320 < AlertDialogContent >
316321 < AlertDialogHeader >
317322 < AlertDialogTitle > { REMOVAL_COPY [ pendingRemoval . kind ] . title } </ AlertDialogTitle >
@@ -321,10 +326,10 @@ const CostTrackingSettings: React.FC<CostTrackingSettingsProps> = ({ userID, use
321326 </ AlertDialogDescription >
322327 </ AlertDialogHeader >
323328 < AlertDialogFooter >
324- < AlertDialogCancel > Cancel</ AlertDialogCancel >
325- < AlertDialogAction variant = "destructive" onClick = { handleConfirmRemoval } >
326- Remove
327- </ AlertDialogAction >
329+ < AlertDialogCancel disabled = { isRemoving } > Cancel</ AlertDialogCancel >
330+ < Button variant = "destructive" onClick = { handleConfirmRemoval } disabled = { isRemoving } >
331+ { isRemoving ? "Removing…" : " Remove" }
332+ </ Button >
328333 </ AlertDialogFooter >
329334 </ AlertDialogContent >
330335 </ AlertDialog >
0 commit comments