浏览代码

Add frontend for updating data.

Lee Morgan 5 年之前
父节点
当前提交
37c253d5e6
共有 2 个文件被更改,包括 58 次插入4 次删除
  1. 29 2
      views/dashboardPage/bundle.js
  2. 29 2
      views/dashboardPage/js/strands/account.js

+ 29 - 2
views/dashboardPage/bundle.js

@@ -2951,7 +2951,7 @@ module.exports = transactionFilter;
 let account = {
     display: function(){
         document.getElementById("accountStrandTitle").innerText = merchant.name;
-        document.getElementById("accountEmail").placeholder = merchant.email;
+        document.getElementById("accountEmail").value = merchant.email;
 
         document.getElementById("accountUpdate").onclick = ()=>{this.updateData()};
 
@@ -2974,7 +2974,34 @@ let account = {
     },
 
     updateData: function(){
-        console.log("updating data");
+        let data = {
+            email: document.getElementById("accountemail").value
+        }
+
+        let loader = document.getElementById("loaderContainer");
+        loader.style.display = "flex";
+
+        fetch("/merchant/update", {
+            method: "post",
+            headers: {
+                "Content-Type": "application/json;charset=utf-8"
+            },
+            body: JSON.stringify(data)
+        })
+            .then(response => response.json())
+            .then((response)=>{
+                if(typeof(response) === "string"){
+                    controller.createBanner(response, "error");
+                }else{
+
+                }
+            })
+            .catch((err)=>{
+                controller.createBanner("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE", "error");
+            })
+            .finally(()=>{
+                loader.style.display = "none";
+            });
     },
 
     updatePassword: function(){

+ 29 - 2
views/dashboardPage/js/strands/account.js

@@ -1,7 +1,7 @@
 let account = {
     display: function(){
         document.getElementById("accountStrandTitle").innerText = merchant.name;
-        document.getElementById("accountEmail").placeholder = merchant.email;
+        document.getElementById("accountEmail").value = merchant.email;
 
         document.getElementById("accountUpdate").onclick = ()=>{this.updateData()};
 
@@ -24,7 +24,34 @@ let account = {
     },
 
     updateData: function(){
-        console.log("updating data");
+        let data = {
+            email: document.getElementById("accountemail").value
+        }
+
+        let loader = document.getElementById("loaderContainer");
+        loader.style.display = "flex";
+
+        fetch("/merchant/update", {
+            method: "post",
+            headers: {
+                "Content-Type": "application/json;charset=utf-8"
+            },
+            body: JSON.stringify(data)
+        })
+            .then(response => response.json())
+            .then((response)=>{
+                if(typeof(response) === "string"){
+                    controller.createBanner(response, "error");
+                }else{
+
+                }
+            })
+            .catch((err)=>{
+                controller.createBanner("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE", "error");
+            })
+            .finally(()=>{
+                loader.style.display = "none";
+            });
     },
 
     updatePassword: function(){