account.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. let account = {
  2. display: function(){
  3. document.getElementById("accountStrandTitle").innerText = merchant.name;
  4. document.getElementById("accountEmail").value = merchant.email;
  5. document.getElementById("accountUpdate").onclick = ()=>{this.updateData()};
  6. let passButton = document.getElementById("accountShowPassword");
  7. let passBox = document.getElementById("changePasswordBox");
  8. passButton.onclick = ()=>{
  9. passButton.style.display = "none";
  10. passBox.style.display = "flex";
  11. };
  12. document.getElementById("cancelPasswordChange").onclick = ()=>{
  13. passButton.style.display = "block";
  14. passBox.style.display = "none";
  15. document.getElementById("accountCurrentPassword").value = "";
  16. document.getElementById("accountNewPassword").value = "";
  17. document.getElementById("accountConfirmPassword").value = "";
  18. };
  19. document.getElementById("changePasswordButton").onclick = ()=>{this.updatePassword()};
  20. },
  21. updateData: function(){
  22. let data = {
  23. email: document.getElementById("accountEmail").value
  24. }
  25. let loader = document.getElementById("loaderContainer");
  26. loader.style.display = "flex";
  27. fetch("/merchant/update", {
  28. method: "put",
  29. headers: {
  30. "Content-Type": "application/json;charset=utf-8"
  31. },
  32. body: JSON.stringify(data)
  33. })
  34. .then(response => response.json())
  35. .then((response)=>{
  36. if(typeof(response) === "string"){
  37. controller.createBanner(response, "error");
  38. }else{
  39. }
  40. })
  41. .catch((err)=>{
  42. controller.createBanner("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE", "error");
  43. })
  44. .finally(()=>{
  45. loader.style.display = "none";
  46. });
  47. },
  48. updatePassword: function(){
  49. console.log("updating password");
  50. }
  51. }
  52. module.exports = account;