Parcourir la source

Transactions can now be removed fromboth front and backend

Lee Morgan il y a 6 ans
Parent
commit
853b6a5603

+ 14 - 5
views/dashboardPage/Merchant.js

@@ -216,12 +216,21 @@ class Merchant{
         closeSidebar();
     }
 
-    // editTransactions(transaction, remove = false){
-    //     for(let )
-    //     if(remove){
+    editTransactions(transaction, remove = false){
+        for(let i = 0; i < this.transactions.length; i++){
+            if(this.transactions[i] === transaction){
+                if(remove){
+                    this.transactions.splice(i, 1);
+                }
 
-    //     }
-    // }
+                break;
+            }
+        }
+
+        transactionsStrandObj.isPopulated = false;
+        transactionsStrandObj.display();
+        closeSidebar();
+    }
 
     /*
     Gets the indices of two dates from transactions

+ 2 - 1
views/dashboardPage/sidebars/sidebars.js

@@ -919,7 +919,8 @@ let transactionDetailsComp = {
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
-                    //update the transactions on the front end
+                    merchant.editTransactions(this.transaction, true);
+                    banner.createNotification("Transaction removed");
                 }
             })
             .catch((err)=>{

+ 4 - 0
views/dashboardPage/transactions.js

@@ -6,6 +6,10 @@ window.transactionsStrandObj = {
             let transactionsList = document.getElementById("transactionsList");
             let template = document.getElementById("transaction").content.children[0];
 
+            while(transactionsList.children.length > 0){
+                transactionsList.removeChild(transactionsList.firstChild);
+            }
+
             for(let i = merchant.transactions.length - 1; i > merchant.transactions.length - 101 ; i--){
                 let transaction = template.cloneNode(true);
                 transaction.onclick = ()=>{transactionDetailsComp.display(merchant.transactions[i])};