From 221bf712f6d1cdbfce4fbf74e09fd8fd541d9c8d Mon Sep 17 00:00:00 2001
From: unknown <13521043@std.stei.itb.ac.id>
Date: Thu, 16 Nov 2023 22:15:20 +0700
Subject: [PATCH] fix: button display in application page

---
 src/admin/gym/application/index.php      |  2 +-
 src/public/javascript/gym/application.js | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/admin/gym/application/index.php b/src/admin/gym/application/index.php
index 7017ef3..c951425 100644
--- a/src/admin/gym/application/index.php
+++ b/src/admin/gym/application/index.php
@@ -35,7 +35,7 @@ AuthMiddleware::getInstance()->secureRoute(true);
         </div>
         <div class="space"></div>
         
-        <div class="first-line-button">
+        <div class="first-line-button" id="button-acc-rej-trainer">
             <button class="button-filter" id="accept-trainer" onclick="showPopupAcc();">
                 Accept Trainer
             </button>
diff --git a/src/public/javascript/gym/application.js b/src/public/javascript/gym/application.js
index c930a01..ea496dc 100644
--- a/src/public/javascript/gym/application.js
+++ b/src/public/javascript/gym/application.js
@@ -83,14 +83,22 @@ function getApplication(username, gymId) {
 
 function acceptApplication(gymId, username) {
   hidePopupAcc()
+  const button = document.getElementById("button-acc-rej-trainer");
+  // hide button
+  button.style.display = "none";
   const xhr = new XMLHttpRequest();
   xhr.onreadystatechange = function () {
       if (this.readyState === 4) {
           if (this.status === 200) {
               alert("accept with username: " + username + " and gym id: " + gymId + "\n" + "Email has been sent to the trainer");
+              // redirect to gym page /admin/gym/?gym_id=${gymId}
+              window.location.href = `/admin/gym/?gym_id=${gymId}`;
           } else {
               const xml = this.responseXML;
               console.log("error status : " + this.status + " error text : " + xml);
+              alert("error status : " + this.status + " error text : " + xml);
+              // show button
+              button.style.display = "flex";
           }
       }
   };
@@ -112,14 +120,22 @@ function acceptApplication(gymId, username) {
 
 function rejectApplication(gymId, username) {
   hidePopupRej()
+  const button = document.getElementById("button-acc-rej-trainer");
+  // hide button
+  button.style.display = "none";
   const xhr = new XMLHttpRequest();
   xhr.onreadystatechange = function () {
       if (this.readyState === 4) {
           if (this.status === 200) {
               alert("reject with username: " + username + " and gym id: " + gymId + "\n" + "Email has been sent to the trainer");
+              // redirect to gym page /admin/gym/?gym_id=${gymId}
+              window.location.href = `/admin/gym/?gym_id=${gymId}`;
           } else {
               const xml = this.responseXML;
               console.log("error status : " + this.status + " error text : " + xml);
+              alert("error status : " + this.status + " error text : " + xml);
+              // show button
+              button.style.display = "flex";
           }
       }
   };
-- 
GitLab