-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.html
More file actions
411 lines (362 loc) · 11.6 KB
/
Copy pathdashboard.html
File metadata and controls
411 lines (362 loc) · 11.6 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Member Dashboard - Gym</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&family=Montserrat:wght@700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
:root {
--primary: #ff4757;
--secondary: #2f3542;
--light: #f1f2f6;
--dark: #1e272e;
--success: #2ed573;
--info: #1e90ff;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url('https://images.unsplash.com/photo-1571902943202-507ec2618e8f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1075&q=80') no-repeat center center fixed;
background-size: cover;
color: var(--light);
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 2rem;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 3rem;
padding-bottom: 1rem;
border-bottom: 2px solid var(--primary);
}
.welcome {
font-size: 2.5rem;
font-weight: 700;
font-family: 'Montserrat', sans-serif;
text-transform: uppercase;
color: white;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
.welcome span {
color: var(--primary);
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0.8rem 1.8rem;
background: var(--primary);
color: white;
font-size: 1rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
border: none;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(255, 71, 87, 0.4);
}
.btn:hover {
transform: translateY(-3px);
box-shadow: 0 6px 20px rgba(255, 71, 87, 0.6);
}
.btn:active {
transform: translateY(-1px);
}
.btn i {
margin-right: 8px;
}
.btn-logout {
background: var(--secondary);
box-shadow: 0 4px 15px rgba(47, 53, 66, 0.4);
}
.btn-logout:hover {
box-shadow: 0 6px 20px rgba(47, 53, 66, 0.6);
}
.dashboard-section {
background: rgba(30, 39, 46, 0.8);
border-radius: 15px;
padding: 2rem;
margin-bottom: 2rem;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.section-title {
font-size: 1.8rem;
margin-bottom: 1.5rem;
color: var(--primary);
position: relative;
padding-bottom: 0.5rem;
font-family: 'Montserrat', sans-serif;
}
.section-title::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 60px;
height: 3px;
background: var(--primary);
}
.quick-actions {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.5rem;
margin-bottom: 2rem;
}
.data-cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 1.5rem;
}
.card {
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
padding: 1.5rem;
transition: all 0.3s ease;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.card:hover {
transform: translateY(-5px);
background: rgba(255, 255, 255, 0.15);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}
.card-title {
font-size: 1.2rem;
margin-bottom: 1rem;
font-weight: 600;
color: var(--primary);
}
.card-value {
font-size: 1.5rem;
font-weight: 700;
margin-bottom: 0.5rem;
}
.card-desc {
font-size: 0.9rem;
opacity: 0.8;
}
.attendance-list {
margin-top: 1rem;
max-height: 300px;
overflow-y: auto;
}
.attendance-item {
padding: 0.8rem;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
display: flex;
justify-content: space-between;
}
.attendance-item:last-child {
border-bottom: none;
}
#message {
position: fixed;
bottom: 2rem;
right: 2rem;
padding: 1rem 2rem;
background: var(--success);
color: white;
border-radius: 50px;
font-weight: 600;
box-shadow: 0 5px 15px rgba(46, 213, 115, 0.4);
display: none;
z-index: 1000;
animation: slideIn 0.5s ease forwards;
}
@keyframes slideIn {
from {
transform: translateX(100%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
@media (max-width: 768px) {
.welcome {
font-size: 1.8rem;
}
.quick-actions, .data-cards {
grid-template-columns: 1fr;
}
header {
flex-direction: column;
gap: 1rem;
text-align: center;
}
}
</style>
</head>
<body>
<div class="container">
<header>
<h1 class="welcome">Welcome, <span id="user-name">Member</span></h1>
<button id="logout" class="btn btn-logout"><i class="fas fa-sign-out-alt"></i> Logout</button>
</header>
<section class="dashboard-section">
<h2 class="section-title">Quick Actions</h2>
<div class="quick-actions">
<div class="card">
<button id="mark-attendance" class="btn" style="width: 100%">
<i class="fas fa-calendar-check"></i> Mark Today's Attendance
</button>
</div>
</div>
<h2 class="section-title">Your Stats</h2>
<div class="data-cards">
<div class="card">
<h3 class="card-title">Membership Status</h3>
<div class="card-value" id="membership-status">Active</div>
<p class="card-desc" id="membership-end-date">Expires: Loading...</p>
</div>
<div class="card">
<h3 class="card-title">Total Visits</h3>
<div class="card-value" id="total-visits">0</div>
<p class="card-desc">Your gym attendance</p>
</div>
<div class="card">
<h3 class="card-title">Recent Attendance</h3>
<div class="attendance-list" id="attendance-list">
<div class="attendance-item">
<span>Loading...</span>
</div>
</div>
</div>
</div>
</section>
<div id="message"></div>
</div>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.3.1/firebase-app.js";
import { getAuth, signOut, onAuthStateChanged } from "https://www.gstatic.com/firebasejs/10.3.1/firebase-auth.js";
import {
getFirestore, doc, getDoc, setDoc,
updateDoc, arrayUnion, serverTimestamp
} from "https://www.gstatic.com/firebasejs/10.3.1/firebase-firestore.js";
const firebaseConfig = {
apiKey: "AIzaSyBXKiAKmQXJxxYJdBMiF7nuSkNXrotEW1I",
authDomain: "gymwebsite-5df52.firebaseapp.com",
projectId: "gymwebsite-5df52",
storageBucket: "gymwebsite-5df52.appspot.com",
messagingSenderId: "494794343106",
appId: "1:494794343106:web:5d9e7ca706286878c3b15b",
measurementId: "G-KJHSRY9XCC"
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);
const userNameSpan = document.getElementById('user-name');
const logoutBtn = document.getElementById('logout');
const markAttendanceBtn = document.getElementById('mark-attendance');
const membershipStatus = document.getElementById('membership-status');
const membershipEndDate = document.getElementById('membership-end-date');
const totalVisits = document.getElementById('total-visits');
const attendanceList = document.getElementById('attendance-list');
const messageDiv = document.getElementById('message');
function formatDate(dateString) {
if (!dateString) return "N/A";
try {
return new Date(dateString).toLocaleDateString('en-US', {
weekday: 'short', year: 'numeric', month: 'short', day: 'numeric'
});
} catch {
return "Invalid Date";
}
}
function formatTimestamp(ts) {
return ts?.toDate ? formatDate(ts.toDate()) : "N/A";
}
function showMessage(msg, isError = false) {
messageDiv.style.background = isError ? "#ff4757" : "#2ed573";
messageDiv.textContent = msg;
messageDiv.style.display = "block";
setTimeout(() => { messageDiv.style.display = "none"; }, 4000);
}
onAuthStateChanged(auth, async (user) => {
if (!user) return (window.location.href = "login.html");
const uid = user.uid;
const ref = doc(db, "members", uid);
try {
let snap = await getDoc(ref);
if (!snap.exists()) {
await setDoc(ref, {
name: user.displayName || "Member",
email: user.email,
createdAt: serverTimestamp(),
membership: {
status: "Pending",
startDate: new Date().toISOString(),
endDate: new Date(new Date().setDate(new Date().getDate() + 30)).toISOString()
},
attendance: []
});
snap = await getDoc(ref);
showMessage("🎉 Welcome! Profile created.");
}
const data = snap.data();
userNameSpan.textContent = data.name || "Member";
const mem = data.membership || {};
membershipStatus.textContent = mem.status || "Pending";
membershipEndDate.textContent = `Expires: ${formatDate(mem.endDate)}`;
const attendance = Array.isArray(data.attendance) ? data.attendance : [];
totalVisits.textContent = attendance.length;
attendanceList.innerHTML = "";
if (attendance.length === 0) {
attendanceList.innerHTML = '<div class="attendance-item">No attendance records yet</div>';
} else {
attendance.sort((a, b) => (b.date?.seconds || 0) - (a.date?.seconds || 0))
.slice(0, 5)
.forEach((record) => {
const div = document.createElement("div");
div.className = "attendance-item";
div.innerHTML = `<span>${formatTimestamp(record.date)}</span> <span>${record.type || 'Visit'}</span>`;
attendanceList.appendChild(div);
});
}
} catch (err) {
console.error("Error:", err.message);
showMessage("⚠️ Error loading data", true);
}
});
logoutBtn.addEventListener('click', async () => {
try {
await signOut(auth);
window.location.href = "login.html";
} catch (err) {
showMessage("⚠️ Logout failed", true);
}
});
markAttendanceBtn.addEventListener('click', async () => {
const user = auth.currentUser;
if (!user) return showMessage("⚠️ Not authenticated", true);
try {
const ref = doc(db, "members", user.uid);
await updateDoc(ref, {
attendance: arrayUnion({
date: serverTimestamp(),
type: "gym_visit"
})
});
showMessage("✅ Attendance marked!");
location.reload(); // Refresh data
} catch (err) {
console.error("Attendance error:", err.message);
showMessage("⚠️ Could not mark attendance", true);
}
});
</script>
</body>
</html>