Bladeren bron

Add confirm modal for deleting transactions.
Fix error caused in development by the new cookie settings.

Lee Morgan 5 jaren geleden
bovenliggende
commit
eb589fb62a

+ 2 - 2
app.js

@@ -18,8 +18,7 @@ app.set("view engine", "ejs");
 
 let sessionOptions = {
     secret: "Super Secret Subline Subliminally Saving Secrets So Sneaky Snakes Stay Sullen. Simply Superb.",
-    secure: true,
-    sameSite: "strict",
+    sameSite: "lax",
     saveUninitialized: true,
     resave: false,
 }
@@ -41,6 +40,7 @@ if(process.env.NODE_ENV === "production"){
     });
 
     sessionOptions.domain = process.env.COOKIE_DOMAIN;
+    sessionOptions.secure = true;
 }
 
 app.use(compression());

+ 0 - 2
controllers/recipeData.js

@@ -95,8 +95,6 @@ module.exports = {
     removeRecipe: function(req, res){
         if(res.locals.merchant.pos === "square") return res.json("YOU MUST EDIT YOUR RECIPES INSIDE SQUARE");
         
-        console.log(res.locals.merchant.recipes);
-        console.log();
         for(let i = 0; i < res.locals.merchant.recipes.length; i++){
             if(res.locals.merchant.recipes[i].toString() === req.params.id){
                 res.locals.merchant.recipes.splice(i, 1);

+ 6 - 8
views/dashboardPage/ejs/sidebars/transactionDetails.ejs

@@ -7,14 +7,12 @@
             </svg>
         </button>
 
-        <% if(merchant.pos === "none"){ %>
-            <button id="removeTransBtn" class="iconButton">
-                <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
-                    <polyline points="3 6 5 6 21 6"></polyline>
-                    <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
-                </svg>
-            </button>
-        <% } %>
+        <button id="removeTransBtn" class="iconButton">
+            <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
+                <polyline points="3 6 5 6 21 6"></polyline>
+                <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
+            </svg>
+        </button>
     </div>
 
     <h1 id="transactionDate"></h1>

+ 7 - 0
views/dashboardPage/js/dashboard.js

@@ -258,6 +258,13 @@ controller = {
                 content.children[2].children[0].onclick = ()=>{controller.closeModal()};
                 content.children[2].children[1].onclick = ()=>{orderDetails.remove(data)};
                 break;
+            case "confirmDeleteTransaction":
+                content = document.getElementById("modalConfirm");
+                content.style.display = "flex";
+                content.children[1].innerText = `Are you sure you want to delete this transaction?`;
+                content.children[2].children[0].onclick = ()=>{controller.closeModal()};
+                content.children[2].children[1].onclick = ()=>{transactionDetails.remove(data)};
+                break;
             case "squareLocations":
                 modalScript.squareLocations(data);
                 break;

+ 9 - 2
views/dashboardPage/js/sidebars/transactionDetails.js

@@ -38,8 +38,14 @@ let transactionDetails = {
         document.getElementById("totalRecipes").innerText = `${totalRecipes} recipes`;
         document.getElementById("totalPrice").innerText = `$${totalPrice.toFixed(2)}`;
 
-        if(merchant.pos === "none"){
-            document.getElementById("removeTransBtn").onclick = ()=>{this.remove()};
+        let button = document.getElementById("removeTransBtn");
+        switch(merchant.pos){
+            case "square":
+                button.style.display = "none";
+                break;
+            case "none":
+                button.style.display = "block";
+                button.onclick = ()=>{controller.openModal("confirmDeleteTransaction", transaction)};
         }
     },
 
@@ -61,6 +67,7 @@ let transactionDetails = {
                     state.updateTransactions();
 
                     controller.openStrand("transactions", merchant.getTransactions());
+                    controller.closeModal();
                     controller.createBanner("TRANSACTION REMOVED", "success");
                 }
             })