diff --git a/Expense-Tracker-Frontend/script.js b/Expense-Tracker-Frontend/script.js
index fda276d..c1293c8 100644
--- a/Expense-Tracker-Frontend/script.js
+++ b/Expense-Tracker-Frontend/script.js
@@ -38,7 +38,7 @@ function updateValues() {
function addTransactionDOM(transaction) {
const tr = document.createElement("tr");
tr.innerHTML = `
-
${transaction.date} |
+ ${formatDate(transaction.date)} |
${transaction.text} |
{
- transactions = transactions.filter((t) => t.id !== id);
- updateUI();
+ const confirmed = confirm(
+ "Are you sure you want to delete this transaction?"
+ );
+
+ if (confirmed) {
+ fetch(`http://localhost:8080/ExpTrack/transactions/${username}/${id}`, {
+ method: "DELETE",
})
- .catch((err) => console.error("Delete failed", err));
+ .then(() => {
+ transactions = transactions.filter((t) => t.id !== id);
+ updateUI();
+ })
+ .catch((err) => console.error("Delete failed", err));
+ }
}
function updateUI() {
@@ -108,3 +114,14 @@ function init() {
}
init();
+
+function formatDate(isoDate) {
+ const date = new Date(isoDate);
+
+ // Get day, month, and year
+ const day = String(date.getDate()).padStart(2, "0");
+ const month = String(date.getMonth() + 1).padStart(2, "0");
+ const year = date.getFullYear();
+
+ return `${day}-${month}-${year}`;
+}
\ No newline at end of file
|