From 1e6810d8e5a29e077987c588070029dfac595892 Mon Sep 17 00:00:00 2001 From: Hidayatullah Wildan Ghaly Buchary <16521502@std.stei.itb.ac.id> Date: Sat, 7 Oct 2023 19:49:20 +0700 Subject: [PATCH] feat: add confirm on js b4 call BE (CHALLENGE) --- public/js/challenge-claim.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/public/js/challenge-claim.js b/public/js/challenge-claim.js index d6442cf..dffeb2f 100644 --- a/public/js/challenge-claim.js +++ b/public/js/challenge-claim.js @@ -1,6 +1,9 @@ document.write('<script src="../../../public/js/api.js"></script>'); function claimFunction(user_id, quest_id){ + if (!confirm("Claim this quest?")) { + return; + } console.log("claimFunction() called"); var url = `${SERVER_PATH}challenge/claim.php`; const xhr = new XMLHttpRequest(); @@ -10,6 +13,7 @@ function claimFunction(user_id, quest_id){ if (xhr.readyState === 4 && xhr.status === 200) { console.log(this.responseText); // const response = JSON.parse(xhr.responseText); + window.location.reload(); } }; const data = `user_id=${encodeURIComponent(user_id)}&quest_id=${encodeURIComponent(quest_id)}` @@ -17,15 +21,19 @@ function claimFunction(user_id, quest_id){ } function unclaimFunction(user_id, quest_id){ + if (!confirm("Unclaim this quest?")) { + return; + } console.log("unclaimFunction() called"); var url = `${SERVER_PATH}challenge/unclaim.php`; const xhr = new XMLHttpRequest(); - xhr.open('POST', url, true); + xhr.open('DELETE', url, true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { console.log(this.responseText); // const response = JSON.parse(xhr.responseText); + window.location.reload(); } }; const data = `user_id=${encodeURIComponent(user_id)}&quest_id=${encodeURIComponent(quest_id)}` -- GitLab