-
Notifications
You must be signed in to change notification settings - Fork 0
/
leavegroup.js
43 lines (33 loc) · 1.56 KB
/
leavegroup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//DO THIS IF THERE IS A LEAVE BUTTON TO LEAVE THE GROUP(OTHERWISE YOU WILL GET ERROR FOR UNDEFINED VARIABLES)
if (document.querySelector("#leave-button")) {
let leaveButton = document.querySelector("#leave-button");
let idUser = document.querySelector("#user-id").innerText;
let idGroup = document.querySelector("#group-id").innerText;
leaveButton.addEventListener("click", async function () {
try {
// SEND A REQUEST TO DELETE THE MEMBER FROM THE GROUP
let response = await axios.post("http://localhost/webproject/leavegroup.php",
{
userID: idUser,
groupID: idGroup
});
if (response.data.success) {
//refrech the page to show the join group button and show the success div
window.location.href = "groupprofile.php?groupid=" + idGroup + "&group-left=" + true;
}
else {
//show the error div
let errorDiv = document.querySelector("#leave-error");
errorDiv.style.display = "block";
let errorWord = document.querySelector("#error-word");
errorWord.innerText = "You Couldn\'t Leave This Group";
}
}
catch (error) {
let errorDiv = document.querySelector("#join-error");
errorDiv.style.display = "block";
let errorWord = document.querySelector("#error-word");
errorWord.innerText = error;
}
});
}