Skip to content

Commit 8f59abb

Browse files
committed
Fix notification messages on Create and Delete action
1 parent 9431b78 commit 8f59abb

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

frontend/src/app/(auth)/leetcode-dashboard/EditQuestionDialog.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,11 @@ const EditQuestionDialog = ({
9393
questionId: questionId,
9494
})
9595
.then((response) => {
96-
if (response.ok) {
97-
Swal.fire({
98-
icon: "success",
99-
title: "Question Added",
100-
text: "Question has been modified successfully.",
101-
});
102-
}
103-
104-
return response.json();
96+
Swal.fire({
97+
icon: "success",
98+
title: "Question Added",
99+
text: "Question has been modified successfully.",
100+
});
105101
})
106102
.catch((error) => {
107103
Swal.fire({

frontend/src/app/(auth)/leetcode-dashboard/LeetcodeDashboardTable.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,31 @@ const Cell = ({
4747
export function LeetcodeDashboardTable() {
4848
const [data, setData] = useState<QuestionMinified[]>([]);
4949
const [modalIsOpen, setIsOpen] = useState(false);
50+
const [isDeleting, setIsDeleting] = useState(false);
5051
const [editingQuestionId, setEditingQuestionId] = React.useState<
5152
string | null
5253
>(null);
5354

5455
function handleDelete(questionId: string) {
56+
setIsDeleting(true);
5557
Swal.fire({
56-
icon: "error",
58+
icon: "warning",
5759
title: "Confirm delete?",
5860
text: "Are you sure you want to delete this question?",
5961
showCancelButton: true,
6062
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);
6872
}
69-
}
73+
},
74+
allowOutsideClick: () => !Swal.isLoading(),
7075
});
7176
}
7277

@@ -163,7 +168,7 @@ export function LeetcodeDashboardTable() {
163168

164169
useEffect(() => {
165170
getLeetcodeDashboardData().then((data) => setData(data));
166-
}, []);
171+
}, [data]);
167172

168173
const table = useReactTable({
169174
data,

0 commit comments

Comments
 (0)