-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage-members.html
More file actions
213 lines (183 loc) · 5.41 KB
/
Copy pathmanage-members.html
File metadata and controls
213 lines (183 loc) · 5.41 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Manage Members</title>
<style>
body {
margin: 0;
padding: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: url('https://images.unsplash.com/photo-1558611848-73f7eb4001a1?auto=format&fit=crop&w=1740&q=80') no-repeat center center fixed;
background-size: cover;
backdrop-filter: blur(5px);
color: #fff;
}
.overlay {
background-color: rgba(0, 0, 0, 0.7);
min-height: 100vh;
padding: 2rem;
}
h1 {
text-align: center;
color: #ff6b6b;
margin-bottom: 30px;
}
.container {
max-width: 1200px;
margin: auto;
}
.cards-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
gap: 20px;
}
.member-card {
background: #fff;
color: #2f3640;
border-radius: 12px;
padding: 1.5rem;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.member-card:hover {
transform: translateY(-4px);
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.4);
}
.member-card h3 {
margin-top: 0;
color: #ff4757;
}
.member-card p {
margin: 8px 0;
font-size: 0.95rem;
}
.controls {
margin-top: 1.2rem;
display: flex;
flex-direction: column;
gap: 10px;
}
select, input[type="text"] {
padding: 10px;
font-size: 1rem;
border-radius: 6px;
border: 1px solid #ccc;
width: 100%;
}
button {
padding: 10px;
font-weight: bold;
border: none;
border-radius: 6px;
cursor: pointer;
transition: 0.3s;
}
.update-btn {
background-color: #1abc9c;
color: #fff;
}
.update-btn:hover {
background-color: #16a085;
}
.delete-btn {
background-color: #d63031;
color: #fff;
}
.delete-btn:hover {
background-color: #c0392b;
}
@media (max-width: 500px) {
.controls {
flex-direction: column;
}
}
</style>
</head>
<body>
<div class="overlay">
<div class="container">
<h1>Manage Gym Members</h1>
<div id="membersContainer" class="cards-grid"></div>
</div>
</div>
<script type="module">
import { db } from './js/firebase-init.js';
import {
collection,
getDocs,
updateDoc,
deleteDoc,
doc
} from 'https://www.gstatic.com/firebasejs/10.3.1/firebase-firestore.js';
const membersContainer = document.getElementById('membersContainer');
async function loadMembers() {
const snapshot = await getDocs(collection(db, "members"));
membersContainer.innerHTML = "";
snapshot.forEach(docSnap => {
const member = docSnap.data();
const id = docSnap.id;
const card = document.createElement('div');
card.className = "member-card";
card.innerHTML = `
<h3>${member.name} (${member.email})</h3>
<p><strong>Package:</strong> ${member.membership?.package || 'N/A'}</p>
<p><strong>Status:</strong> ${member.membership?.status || 'Pending'}</p>
<p><strong>Start Date:</strong> ${member.membership?.startDate || 'N/A'}</p>
<p><strong>End Date:</strong> ${member.membership?.endDate || 'N/A'}</p>
<p><strong>Alert:</strong> ${member.alert || 'None'}</p>
<div class="controls">
<select id="select-${id}">
<option value="Active">Active</option>
<option value="Hold">Hold</option>
</select>
<input type="text" id="msg-${id}" placeholder="Enter alert message..." />
<button class="update-btn" onclick="updateMember('${id}')">Update</button>
<button class="delete-btn" onclick="deleteMember('${id}')">Delete</button>
</div>
`;
membersContainer.appendChild(card);
});
}
window.updateMember = async function (id) {
const status = document.getElementById(`select-${id}`).value;
const msg = document.getElementById(`msg-${id}`).value;
const today = new Date();
const startDate = today.toISOString().split('T')[0];
const endDate = new Date(today);
endDate.setDate(today.getDate() + 30);
const endDateFormatted = endDate.toISOString().split('T')[0];
const updateData = {
"membership.status": status,
alert: msg
};
if (status === "Active") {
updateData["membership.startDate"] = startDate;
updateData["membership.endDate"] = endDateFormatted;
}
try {
const ref = doc(db, "members", id);
await updateDoc(ref, updateData);
alert("✅ Member updated successfully!");
loadMembers();
} catch (err) {
console.error("Update failed:", err.message);
alert("❌ Error updating member.");
}
};
window.deleteMember = async function (id) {
if (!confirm("Are you sure you want to delete this member?")) return;
try {
await deleteDoc(doc(db, "members", id));
alert("🗑️ Member deleted.");
loadMembers();
} catch (err) {
console.error("Delete failed:", err.message);
alert("❌ Failed to delete member.");
}
};
loadMembers();
</script>
</body>
</html>