@@ -47,26 +47,31 @@ const Cell = ({
47
47
export function LeetcodeDashboardTable ( ) {
48
48
const [ data , setData ] = useState < QuestionMinified [ ] > ( [ ] ) ;
49
49
const [ modalIsOpen , setIsOpen ] = useState ( false ) ;
50
+ const [ isDeleting , setIsDeleting ] = useState ( false ) ;
50
51
const [ editingQuestionId , setEditingQuestionId ] = React . useState <
51
52
string | null
52
53
> ( null ) ;
53
54
54
55
function handleDelete ( questionId : string ) {
56
+ setIsDeleting ( true ) ;
55
57
Swal . fire ( {
56
- icon : "error " ,
58
+ icon : "warning " ,
57
59
title : "Confirm delete?" ,
58
60
text : "Are you sure you want to delete this question?" ,
59
61
showCancelButton : true ,
60
62
confirmButtonText : "Confirm" ,
61
- } ) . then ( async ( result ) => {
62
- if ( result . isConfirmed ) {
63
- const res = await deleteSingleLeetcodeQuestion ( questionId ) ;
64
- if ( res . ok ) {
65
- Swal . fire ( "Question deleted successfully!" , "" , "success" ) ;
66
- } else {
67
- Swal . fire ( "An error occured, please try again later" ) ;
63
+ showLoaderOnConfirm : true ,
64
+ preConfirm : async ( ) => {
65
+ try {
66
+ await deleteSingleLeetcodeQuestion ( questionId ) ;
67
+ return Swal . fire ( "Question deleted successfully!" , "" , "success" ) ;
68
+ } catch ( error ) {
69
+ Swal . showValidationMessage ( `Failed to delete question: ${ error } ` ) ;
70
+ } finally {
71
+ setIsDeleting ( false ) ;
68
72
}
69
- }
73
+ } ,
74
+ allowOutsideClick : ( ) => ! Swal . isLoading ( ) ,
70
75
} ) ;
71
76
}
72
77
@@ -163,7 +168,7 @@ export function LeetcodeDashboardTable() {
163
168
164
169
useEffect ( ( ) => {
165
170
getLeetcodeDashboardData ( ) . then ( ( data ) => setData ( data ) ) ;
166
- } , [ ] ) ;
171
+ } , [ data ] ) ;
167
172
168
173
const table = useReactTable ( {
169
174
data,
0 commit comments