-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
111 lines (101 loc) · 3.7 KB
/
index.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// const deleteUser = async (userId, authToken) => {
// showLoading();
// try {
// const res = await axios({
// method: "DELETE",
// url: `https://mybrandbackend-93l8.onrender.com/api/users/${userId}`,
// headers: { Authorization: `Bearer ${authToken}` },
// });
// hideLoading();
// const row = document.querySelector(`button[data-user-id = ${userId}]`).closest('tr')
// if(row){
// row.remove();
// }
// } catch (error) {
// console.error("Error deleting user:", error);
// }
// };
// const fetchUser = async () => {
// const authtoken = localStorage.getItem("jwt");
// try {
// const res = await axios({
// method: "GET",
// url: "https://mybrandbackend-93l8.onrender.com/api/users",
// headers: { Authorization: `Bearer ${authtoken}` },
// });
// console.log(res.data.data.User);
// const data = res.data.data.User;
// updateTotalUser(data);
// const tbody = document.getElementById("user-content");
// tbody.innerHTML = ""; // Clear previous data
// data.forEach((element, index) => {
// const row = document.createElement("tr");
// row.innerHTML = `
// <td>${index + 1}</td>
// <td>${element.name}</td>
// <td>${element.email}</td>
// <td><a href="#" class="btn">Edit</a></td>
// <td><a href="#" class="btn deleteUser" data-userid="${element._id}">Delete</a></td>`;
// tbody.appendChild(row);
// });
// const deleteButtons = document.querySelectorAll('.deleteUser');
// deleteButtons.forEach((button) => {
// button.addEventListener("click", (event) => {
// const userId = event.target.getAttribute('data-userid');
// console.log(userId);
// console.log("Delete button clicked");
// deleteUser(userId,authtoken);
// });
// });
// } catch (error) {
// console.error("Error fetching user data:", error);
// }
// };
// function updateTotalUser(userData) {
// const totalUsers = userData.length;
// const totalUserElement = document.querySelector("#userNumber");
// if (totalUserElement) {
// totalUserElement.textContent = totalUsers;
// }
// }
// async function displayData() {
// await fetchUser();
// }
const spinner = document.getElementById('loading-spinner');
function showLoading() {
spinner.style.display = 'block';
}
function hideLoading() {
spinner.style.display = 'none';
}
const blog = document.getElementById('blog');
const message = document.getElementById('message');
const dashboard = document.getElementById('dashboard');
const messageContent = document.getElementById('messageBtn')
const blogContent = document.getElementById('blogBtn')
const dashboardContent = document.getElementById('dashboardBtn');
blogContent.addEventListener('click',() => {
blog.style.display = 'block';
message.style.display = 'none';
dashboard.style.display = 'none';
});
messageContent.addEventListener('click',() => {
blog.style.display = 'none';
message.style.display = 'block';
dashboard.style.display = 'none';
});
dashboardContent.addEventListener('click',() => {
blog.style.display = 'none';
message.style.display = 'none';
dashboard.style.display = 'block';
});
function logout() {
localStorage.removeItem('jwt')
window.location.href = './index.html'
}
document.addEventListener("DOMContentLoaded", ()=>{
const token = localStorage.getItem('jwt')
if(!token){
window.location.href = './index.html'
}
})