veltrixcode commited on
Commit
eab827a
·
verified ·
1 Parent(s): f69e04a

Delete public/status.html

Browse files
Files changed (1) hide show
  1. public/status.html +0 -748
public/status.html DELETED
@@ -1,748 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>GCX (Gift Card Exchange) - Track Status</title>
7
- <script src="https://cdn.tailwindcss.com"></script>
8
- <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
9
- <style>
10
- :root { --apple-blue: #0071e3; --apple-gray: #1d1d1f; }
11
- body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
12
- .gradient-bg { background: linear-gradient(135deg, #000000 0%, #1d1d1f 100%); }
13
- .glass-effect { background: rgba(255, 255, 255, 0.08); backdrop-filter: blur(20px); border: 1px solid rgba(255, 255, 255, 0.1); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.37); }
14
- .apple-button { background: var(--apple-blue); border-radius: 980px; font-weight: 500; transition: all 0.3s ease; }
15
- .apple-button:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0, 113, 227, 0.3); }
16
- .apple-input { background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 12px; transition: all 0.3s ease; }
17
- .apple-input:focus { border-color: var(--apple-blue); box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.1); }
18
- .apple-card { background: rgba(255, 255, 255, 0.05); border-radius: 20px; border: 1px solid rgba(255, 255, 255, 0.1); transition: all 0.3s ease; }
19
- .apple-card:hover { transform: translateY(-4px); box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2); }
20
- .status-approved { background: #34d399; } .status-rejected { background: #f87171; } .status-pending { background: #fbbf24; }
21
- .modal-backdrop { backdrop-filter: blur(10px); }
22
- @keyframes spin { to { transform: rotate(360deg); } }
23
- .loading { width: 20px; height: 20px; border: 2px solid rgba(255,255,255,0.3); border-top: 2px solid white; border-radius: 50%; animation: spin 1s linear infinite; }
24
- @media (max-width: 768px) { .chat-container { width: 100vw; height: 100vh; bottom: 0; right: 0; border-radius: 0; } }
25
- </style>
26
- </head>
27
- <body class="min-h-screen gradient-bg text-white">
28
- <!-- Header -->
29
- <header class="w-full glass-effect card-shadow p-6 flex flex-col sm:flex-row items-center justify-between mb-8">
30
- <div class="flex items-center space-x-4">
31
- <img src="logo.png" alt="GCX Logo" class="w-14 h-14 rounded-full bg-white bg-opacity-10 p-2">
32
- <div>
33
- <h1 class="text-3xl font-bold text-white">GCX (Gift Card Exchange)</h1>
34
- <p class="text-white text-opacity-70 text-lg">Track your gift card status</p>
35
- </div>
36
- </div>
37
- <a href="/" class="apple-button text-white px-6 py-3 mt-4 sm:mt-0 font-semibold flex items-center space-x-2">
38
- <i class="fas fa-arrow-left"></i>
39
- <span>Back to Home</span>
40
- </a>
41
- </header>
42
-
43
- <!-- Loading Modal -->
44
- <div id="loadingModal" class="fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50 hidden">
45
- <div class="glass-effect rounded-3xl p-8 text-center">
46
- <div class="animate-spin rounded-full h-12 w-12 border-b-2 border-white mx-auto mb-4"></div>
47
- <p id="loadingMessage" class="text-white text-lg">Processing...</p>
48
- </div>
49
- </div>
50
-
51
- <!-- Main Menu Content -->
52
- <div id="mainMenuContent" class="min-h-screen flex items-center justify-center p-4">
53
- <div class="w-full max-w-4xl">
54
- <!-- Header -->
55
- <div class="text-center mb-12">
56
- <div class="w-24 h-24 mx-auto mb-6 bg-white bg-opacity-10 rounded-3xl flex items-center justify-center">
57
- <i class="fas fa-gift text-4xl text-white"></i>
58
- </div>
59
- <h1 class="text-5xl font-bold mb-4">GCX</h1>
60
- <p class="text-2xl text-white text-opacity-80 mb-2">Gift Card Exchange</p>
61
- <p class="text-white text-opacity-60">Track your gift card status</p>
62
- </div>
63
-
64
- <!-- Track Status Button -->
65
- <div class="text-center mb-12">
66
- <button id="trackStatusBtn" class="apple-button text-white py-4 px-8 text-xl font-semibold focus:outline-none">
67
- <i class="fas fa-search mr-3"></i>
68
- Track Status
69
- </button>
70
- </div>
71
-
72
- <!-- Features Section -->
73
- <div class="grid grid-cols-1 md:grid-cols-3 gap-8 mb-12">
74
- <div class="bg-white bg-opacity-10 rounded-xl p-6 feature-card">
75
- <div class="w-16 h-16 bg-white bg-opacity-20 rounded-2xl flex items-center justify-center mb-4">
76
- <i class="fas fa-shield-alt text-2xl text-white"></i>
77
- </div>
78
- <h3 class="text-xl font-bold text-white mb-3">Secure Tracking</h3>
79
- <p class="text-white text-opacity-80">Real-time status updates with secure authentication</p>
80
- </div>
81
- <div class="bg-white bg-opacity-10 rounded-xl p-6 feature-card">
82
- <div class="w-16 h-16 bg-white bg-opacity-20 rounded-2xl flex items-center justify-center mb-4">
83
- <i class="fas fa-comments text-2xl text-white"></i>
84
- </div>
85
- <h3 class="text-xl font-bold text-white mb-3">Live Support</h3>
86
- <p class="text-white text-opacity-80">Chat directly with our support team</p>
87
- </div>
88
- <div class="bg-white bg-opacity-10 rounded-xl p-6 feature-card">
89
- <div class="w-16 h-16 bg-white bg-opacity-20 rounded-2xl flex items-center justify-center mb-4">
90
- <i class="fas fa-history text-2xl text-white"></i>
91
- </div>
92
- <h3 class="text-xl font-bold text-white mb-3">Transaction History</h3>
93
- <p class="text-white text-opacity-80">Complete history of all your submissions</p>
94
- </div>
95
- </div>
96
-
97
- <!-- FAQ Section -->
98
- <div class="bg-white bg-opacity-10 rounded-xl p-8 feature-card">
99
- <h3 class="text-3xl font-bold text-white mb-8">🧾 Frequently Asked Questions</h3>
100
- <div class="space-y-8">
101
- <div class="bg-white bg-opacity-5 p-6 rounded-xl">
102
- <h4 class="text-2xl font-bold text-white mb-3">Which gift cards do you support?</h4>
103
- <p class="text-white text-opacity-90 text-lg">Amazon, Overwatch, and Roblox.</p>
104
- </div>
105
- <div class="bg-white bg-opacity-5 p-6 rounded-xl">
106
- <h4 class="text-2xl font-bold text-white mb-3">How do I prove my card is real?</h4>
107
- <p class="text-white text-opacity-90 text-lg">Record a short video showing the card redemption, and upload it during the submission process.</p>
108
- </div>
109
- <div class="bg-white bg-opacity-5 p-6 rounded-xl">
110
- <h4 class="text-2xl font-bold text-white mb-3">Is this legit?</h4>
111
- <p class="text-white text-opacity-90 text-lg">100%. We verify every transaction and offer real-time support.</p>
112
- </div>
113
- </div>
114
- </div>
115
- <!-- Footer -->
116
- <div class="text-center text-white text-opacity-70 mt-12 pb-8">
117
- <p>© 2025 GCX (Gift Card Exchange). All rights reserved.</p>
118
- <div class="mt-4 space-x-4">
119
- <a href="https://www.youtube.com/@shirtlessdigital" class="hover:text-opacity-100">YouTube</a>
120
- <a href="mailto:contact@shirtlessdigital.com" class="hover:text-opacity-100">Email</a>
121
- </div>
122
- </div>
123
- </div>
124
- </div>
125
-
126
- <!-- Auth Section -->
127
- <div id="authSection" class="min-h-screen flex items-center justify-center p-4 hidden">
128
- <div class="w-full max-w-md">
129
- <div class="text-center mb-8">
130
- <div class="w-20 h-20 mx-auto mb-6 bg-white bg-opacity-10 rounded-3xl flex items-center justify-center">
131
- <i class="fas fa-gift text-3xl text-white"></i>
132
- </div>
133
- <h1 class="text-4xl font-bold mb-2">GCX Portal</h1>
134
- <p class="text-white text-opacity-70">Track your gift card status</p>
135
- </div>
136
- <div class="glass-effect rounded-3xl p-8">
137
- <!-- Error Display Area -->
138
- <div id="loginError" class="mb-6 p-4 bg-red-500 bg-opacity-20 border border-red-500 border-opacity-30 rounded-xl hidden">
139
- <p id="loginErrorMessage" class="text-red-300 text-center"></p>
140
- </div>
141
-
142
- <div class="space-y-6">
143
- <div>
144
- <label class="block text-sm font-medium text-white text-opacity-90 mb-3">Email Address</label>
145
- <input type="email" id="email" placeholder="Enter your email" class="apple-input w-full px-4 py-4 text-white placeholder-gray-400 focus:outline-none" onblur="validateEmail()">
146
- <p id="emailError" class="text-red-400 text-sm mt-1 hidden">Please enter a valid email address</p>
147
- </div>
148
- <div>
149
- <label class="block text-sm font-medium text-white text-opacity-90 mb-3">Password</label>
150
- <input type="password" id="password" placeholder="Enter your password" class="apple-input w-full px-4 py-4 text-white placeholder-gray-400 focus:outline-none">
151
- </div>
152
- <button id="loginBtn" onclick="sendOtp()" class="apple-button w-full text-white py-4 px-6 font-semibold focus:outline-none">
153
- <span class="button-text">Continue</span>
154
- <span class="button-loading hidden">
155
- <i class="fas fa-spinner fa-spin mr-2"></i>
156
- Processing...
157
- </span>
158
- </button>
159
- </div>
160
- </div>
161
- </div>
162
- </div>
163
-
164
- <!-- OTP Section -->
165
- <div id="otpSection" class="min-h-screen flex items-center justify-center p-4 hidden">
166
- <div class="w-full max-w-md">
167
- <div class="text-center mb-8">
168
- <div class="w-20 h-20 mx-auto mb-6 bg-white bg-opacity-10 rounded-3xl flex items-center justify-center">
169
- <i class="fas fa-shield-alt text-3xl text-white"></i>
170
- </div>
171
- <h2 class="text-3xl font-bold mb-2">Verify Your Email</h2>
172
- <p class="text-white text-opacity-70">Enter the verification code sent to your email</p>
173
- </div>
174
- <div class="glass-effect rounded-3xl p-8">
175
- <div class="space-y-6">
176
- <div>
177
- <label class="block text-sm font-medium text-white text-opacity-90 mb-3">Verification Code</label>
178
- <input type="text" id="otp" maxlength="6" placeholder="Enter 6-digit code" class="apple-input w-full px-4 py-4 text-white text-center text-2xl tracking-widest focus:outline-none">
179
- </div>
180
- <button id="verifyBtn" onclick="verifyOtp()" class="apple-button w-full text-white py-4 px-6 font-semibold focus:outline-none">
181
- <span class="button-text">Verify & Continue</span>
182
- <span class="button-loading hidden">
183
- <i class="fas fa-spinner fa-spin mr-2"></i>
184
- Processing...
185
- </span>
186
- </button>
187
- </div>
188
- </div>
189
- </div>
190
- </div>
191
-
192
- <!-- Status Section -->
193
- <div id="statusSection" class="min-h-screen p-4 hidden">
194
- <div class="max-w-6xl mx-auto">
195
- <!-- Header -->
196
- <div class="glass-effect rounded-3xl p-6 mb-6">
197
- <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
198
- <div>
199
- <h1 class="text-2xl sm:text-3xl font-bold" id="welcomeText">Welcome back!</h1>
200
- <p class="text-white text-opacity-70">Track your gift card submissions</p>
201
- </div>
202
- <div class="flex flex-col sm:flex-row gap-3 w-full sm:w-auto">
203
- <button onclick="toggleChat()" class="apple-button text-white px-6 py-3 flex items-center justify-center space-x-2">
204
- <i class="fas fa-comments"></i>
205
- <span>Chat</span>
206
- </button>
207
- <button onclick="logout()" class="bg-red-500 hover:bg-red-600 text-white px-6 py-3 rounded-full transition-all flex items-center justify-center space-x-2">
208
- <i class="fas fa-sign-out-alt"></i>
209
- <span>Logout</span>
210
- </button>
211
- </div>
212
- </div>
213
- </div>
214
- <!-- Submissions List -->
215
- <div id="submissionsList" class="space-y-4"></div>
216
- </div>
217
- </div>
218
-
219
- <!-- Chat Section -->
220
- <div id="chatSection" class="fixed bottom-4 right-4 w-96 max-w-full glass-effect rounded-3xl hidden chat-container">
221
- <div class="flex justify-between items-center p-6 border-b border-white border-opacity-20">
222
- <h3 class="font-semibold text-lg">Admin Support</h3>
223
- <button onclick="toggleChat()" class="text-white hover:text-opacity-70 w-8 h-8 flex items-center justify-center">
224
- <i class="fas fa-times"></i>
225
- </button>
226
- </div>
227
- <div id="chatMessages" class="h-80 overflow-y-auto p-4 space-y-4"></div>
228
- <div class="p-4 border-t border-white border-opacity-20">
229
- <div class="flex gap-3">
230
- <input type="text" id="messageInput" placeholder="Type message..." class="apple-input flex-1 px-4 py-3 text-white placeholder-gray-400 text-sm focus:outline-none">
231
- <button onclick="sendMessage()" class="apple-button text-white px-4 py-3">
232
- <i class="fas fa-paper-plane"></i>
233
- </button>
234
- </div>
235
- </div>
236
- </div>
237
-
238
- <!-- Video Modal -->
239
- <div id="videoModal" class="fixed inset-0 bg-black bg-opacity-75 modal-backdrop hidden flex items-center justify-center z-50 p-4">
240
- <div class="glass-effect rounded-3xl p-4 max-w-4xl w-full">
241
- <div class="relative">
242
- <button onclick="closeVideoModal()" class="absolute -top-2 -right-2 bg-red-500 text-white rounded-full w-10 h-10 flex items-center justify-center hover:bg-red-600 transition-all">
243
- <i class="fas fa-times"></i>
244
- </button>
245
- <video id="modalVideo" class="w-full rounded-2xl" controls></video>
246
- </div>
247
- </div>
248
- </div>
249
-
250
- <script>
251
- let userId = null, userEmail = null, currentOtp = null, userName = null, chatInterval = null;
252
- let eventSource = null;
253
-
254
- window.onload = () => clearSession();
255
-
256
- // Initialize EventSource connection
257
- function initializeEventSource() {
258
- if (!userId) return;
259
-
260
- const protocol = window.location.protocol === 'https:' ? 'https:' : 'http:';
261
- const host = window.location.host;
262
-
263
- eventSource = new EventSource(`${protocol}//${host}/events/user/${userId}`, {
264
- headers: {
265
- 'x-otp-token': currentOtp,
266
- 'x-user-email': userEmail,
267
- 'x-user-id': userId
268
- }
269
- });
270
-
271
- eventSource.onopen = () => {
272
- console.log('Connected to chat event stream');
273
- };
274
-
275
- eventSource.onerror = (error) => {
276
- console.error('EventSource error:', error);
277
- };
278
-
279
- eventSource.onmessage = (event) => {
280
- try {
281
- const data = JSON.parse(event.data);
282
- handleEvent(data);
283
- } catch (error) {
284
- console.error('Error parsing event data:', error);
285
- }
286
- };
287
- }
288
-
289
- // Handle different event types
290
- function handleEvent(data) {
291
- switch (data.event) {
292
- case 'connected':
293
- console.log('Connected to event stream:', data.data);
294
- break;
295
-
296
- case 'new-message':
297
- // Only add message if it's for current user
298
- if (data.data.message.user_id === userId) {
299
- addMessageToChat(data.data.message);
300
- }
301
- break;
302
-
303
- case 'user-typing':
304
- if (data.data.userId === userId) {
305
- showTypingIndicator(data.data.userEmail);
306
- }
307
- break;
308
-
309
- case 'user-stopped-typing':
310
- if (data.data.userId === userId) {
311
- hideTypingIndicator();
312
- }
313
- break;
314
-
315
- case 'message-sent':
316
- console.log('Message sent successfully:', data.data);
317
- break;
318
-
319
- case 'message-error':
320
- console.error('Message error:', data.data);
321
- break;
322
-
323
- default:
324
- console.log('Unknown event:', data.event, data.data);
325
- }
326
- }
327
-
328
- // Add message to chat without reloading all messages
329
- function addMessageToChat(message) {
330
- const container = document.getElementById('chatMessages');
331
- if (!container) return;
332
-
333
- // Remove typing indicator if present
334
- hideTypingIndicator();
335
-
336
- const div = document.createElement('div');
337
- div.className = `flex ${message.sender === 'user' ? 'justify-end' : 'justify-start'} mb-3`;
338
- div.innerHTML = `
339
- <div class="max-w-[80%] ${message.sender === 'user' ? 'bg-blue-500' : 'bg-white bg-opacity-20'} rounded-2xl px-4 py-3">
340
- <p class="text-white text-sm">${escapeHtml(message.content)}</p>
341
- <p class="text-white text-opacity-60 text-xs mt-1">${new Date(message.created_at).toLocaleTimeString()}</p>
342
- </div>
343
- `;
344
- container.appendChild(div);
345
- container.scrollTop = container.scrollHeight;
346
-
347
- // Add message to chat history
348
- addMessageToHistory(message);
349
- }
350
-
351
- // Show typing indicator
352
- function showTypingIndicator(userEmail) {
353
- const container = document.getElementById('chatMessages');
354
- if (!container) return;
355
-
356
- // Remove existing typing indicator
357
- hideTypingIndicator();
358
-
359
- const typingDiv = document.createElement('div');
360
- typingDiv.id = 'typing-indicator';
361
- typingDiv.className = 'flex justify-start mb-3';
362
- typingDiv.innerHTML = `
363
- <div class="max-w-[80%] bg-white bg-opacity-20 rounded-2xl px-4 py-3">
364
- <p class="text-white text-sm opacity-70">${userEmail} is typing...</p>
365
- </div>
366
- `;
367
- container.appendChild(typingDiv);
368
- container.scrollTop = container.scrollHeight;
369
- }
370
-
371
- // Hide typing indicator
372
- function hideTypingIndicator() {
373
- const typingIndicator = document.getElementById('typing-indicator');
374
- if (typingIndicator) {
375
- typingIndicator.remove();
376
- }
377
- }
378
-
379
- // Add message to chat history for persistence
380
- function addMessageToHistory(message) {
381
- // Store in session storage for persistence during session
382
- let chatHistory = JSON.parse(sessionStorage.getItem(`chat_${userId}`) || '[]');
383
- chatHistory.push(message);
384
-
385
- // Keep only last 100 messages
386
- if (chatHistory.length > 100) {
387
- chatHistory = chatHistory.slice(-100);
388
- }
389
-
390
- sessionStorage.setItem(`chat_${userId}`, JSON.stringify(chatHistory));
391
- }
392
-
393
- // Escape HTML to prevent XSS
394
- function escapeHtml(text) {
395
- const div = document.createElement('div');
396
- div.textContent = text;
397
- return div.innerHTML;
398
- }
399
-
400
- // Handle typing events
401
- async function handleTyping() {
402
- if (!userId) return;
403
-
404
- try {
405
- await fetch('/api/typing', {
406
- method: 'POST',
407
- headers: {
408
- 'Content-Type': 'application/json',
409
- 'x-otp-token': currentOtp,
410
- 'x-user-email': userEmail
411
- },
412
- body: JSON.stringify({ userId })
413
- });
414
- } catch (error) {
415
- console.error('Error sending typing indicator:', error);
416
- }
417
- }
418
-
419
- // Loading state management
420
- function setLoading(buttonId, isLoading, message = 'Processing...') {
421
- const button = document.getElementById(buttonId);
422
- const buttonText = button.querySelector('.button-text');
423
- const buttonLoading = button.querySelector('.button-loading');
424
-
425
- if (isLoading) {
426
- button.disabled = true;
427
- buttonText.classList.add('hidden');
428
- buttonLoading.classList.remove('hidden');
429
- } else {
430
- button.disabled = false;
431
- buttonText.classList.remove('hidden');
432
- buttonLoading.classList.add('hidden');
433
- }
434
- }
435
-
436
- // Loading modal management
437
- function showLoadingModal(message = 'Processing...') {
438
- document.getElementById('loadingMessage').textContent = message;
439
- document.getElementById('loadingModal').classList.remove('hidden');
440
- console.log('Loading modal shown:', message);
441
- }
442
-
443
- function hideLoadingModal() {
444
- document.getElementById('loadingModal').classList.add('hidden');
445
- console.log('Loading modal hidden');
446
- }
447
-
448
- // Error display management
449
- function showLoginError(message) {
450
- const errorDiv = document.getElementById('loginError');
451
- const errorMessage = document.getElementById('loginErrorMessage');
452
- errorMessage.textContent = message;
453
- errorDiv.classList.remove('hidden');
454
- }
455
-
456
- function hideLoginError() {
457
- document.getElementById('loginError').classList.add('hidden');
458
- }
459
-
460
- // Email validation
461
- function isValidEmail(email) {
462
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
463
- return emailRegex.test(email);
464
- }
465
-
466
- // Session management
467
- function clearSession() {
468
- userId = null;
469
- userEmail = null;
470
- currentOtp = null;
471
- userName = null;
472
- if (chatInterval) {
473
- clearInterval(chatInterval);
474
- chatInterval = null;
475
- }
476
- if (eventSource) {
477
- eventSource.close();
478
- eventSource = null;
479
- }
480
- }
481
-
482
- // Initialize EventSource when user logs in
483
- function initializeUserSession(userData, otp) {
484
- userId = userData.id;
485
- userEmail = userData.email;
486
- userName = userData.name;
487
- currentOtp = otp;
488
-
489
- // Initialize EventSource connection for chat
490
- initializeEventSource();
491
- }
492
-
493
- function logout() { clearSession(); }
494
-
495
- async function sendOtp() {
496
- const email = document.getElementById('email').value;
497
- const password = document.getElementById('password').value;
498
-
499
- // Validation
500
- if (!email || !password) {
501
- showLoginError('Please enter both email and password');
502
- return;
503
- }
504
-
505
- if (!isValidEmail(email)) {
506
- showLoginError('Please enter a valid email address');
507
- return;
508
- }
509
-
510
- hideLoginError();
511
- setLoading('loginBtn', true);
512
- showLoadingModal('Sending verification code...');
513
-
514
- try {
515
- const loginResponse = await fetch('/api/login', {
516
- method: 'POST',
517
- headers: { 'Content-Type': 'application/json' },
518
- body: JSON.stringify({ email, password })
519
- });
520
- const loginData = await loginResponse.json();
521
-
522
- if (!loginData.success) {
523
- hideLoadingModal();
524
- setLoading('loginBtn', false);
525
- showLoginError(loginData.error || 'Invalid email or password');
526
- return;
527
- }
528
-
529
- userId = loginData.user.id;
530
- userEmail = email;
531
- userName = loginData.user.name;
532
-
533
- const otpResponse = await fetch('/api/send-otp', {
534
- method: 'POST',
535
- headers: { 'Content-Type': 'application/json' },
536
- body: JSON.stringify({ email, type: 'login' })
537
- });
538
- const otpData = await otpResponse.json();
539
-
540
- hideLoadingModal();
541
- setLoading('loginBtn', false);
542
-
543
- if (otpData.success) {
544
- document.getElementById('authSection').classList.add('hidden');
545
- document.getElementById('otpSection').classList.remove('hidden');
546
- document.getElementById('otp').focus();
547
- initializeUserSession(loginData.user, otpData.otp);
548
- } else {
549
- showLoginError(otpData.error || 'Failed to send OTP');
550
- }
551
- } catch (error) {
552
- console.error('Error:', error);
553
- hideLoadingModal();
554
- setLoading('loginBtn', false);
555
- showLoginError('Failed to send OTP. Please try again.');
556
- }
557
- }
558
-
559
- async function verifyOtp() {
560
- const otp = document.getElementById('otp').value;
561
- if (!otp) {
562
- alert('Please enter the OTP');
563
- return;
564
- }
565
-
566
- setLoading('verifyBtn', true);
567
- showLoadingModal('Verifying code...');
568
-
569
- try {
570
- const response = await fetch('/api/verify-otp', {
571
- method: 'POST',
572
- headers: { 'Content-Type': 'application/json' },
573
- body: JSON.stringify({ email: userEmail, otp, type: 'login' })
574
- });
575
- const data = await response.json();
576
-
577
- hideLoadingModal();
578
- setLoading('verifyBtn', false);
579
-
580
- if (data.success) {
581
- currentOtp = otp;
582
- document.getElementById('otpSection').classList.add('hidden');
583
- document.getElementById('statusSection').classList.remove('hidden');
584
- document.getElementById('welcomeText').textContent = `Welcome back, ${userName}!`;
585
- loadSubmissions();
586
- } else {
587
- alert(data.error || 'OTP verification failed');
588
- }
589
- } catch (error) {
590
- console.error('Error:', error);
591
- hideLoadingModal();
592
- setLoading('verifyBtn', false);
593
- alert('Failed to verify OTP. Please try again.');
594
- }
595
- }
596
-
597
- async function loadSubmissions() {
598
- if (!userId || !userEmail || !currentOtp) return clearSession();
599
-
600
- try {
601
- const response = await fetch(`/api/user-submissions/${userId}`, {
602
- headers: { 'x-otp-token': currentOtp, 'x-user-email': userEmail }
603
- });
604
- const data = await response.json();
605
- if (!data.success) throw new Error(data.error || 'Failed to load submissions');
606
-
607
- const list = document.getElementById('submissionsList');
608
- list.innerHTML = data.submissions.length === 0 ? `
609
- <div class="text-center py-16 apple-card">
610
- <i class="fas fa-inbox text-4xl text-white text-opacity-50 mb-4"></i>
611
- <p class="text-white text-opacity-80 text-lg">No submissions found</p>
612
- <p class="text-white text-opacity-60">Your gift cards will appear here</p>
613
- </div>
614
- ` : '';
615
-
616
- data.submissions.forEach(submission => {
617
- const statusColors = { approved: 'status-approved', rejected: 'status-rejected', pending: 'status-pending' };
618
- const card = document.createElement('div');
619
- card.className = 'apple-card p-6';
620
- card.innerHTML = `
621
- <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center mb-4 gap-2">
622
- <span class="text-white text-opacity-70 text-sm">${new Date(submission.created_at).toLocaleDateString()}</span>
623
- <span class="px-4 py-2 text-xs font-semibold rounded-full text-white ${statusColors[submission.status] || 'bg-gray-500'}">
624
- ${submission.status.toUpperCase()}
625
- </span>
626
- </div>
627
- <div class="grid grid-cols-1 sm:grid-cols-2 gap-4 text-white">
628
- <p><span class="text-opacity-70 text-white">UID:</span> ${submission.id}</p>
629
- <p><span class="text-opacity-70 text-white">Card:</span> ${submission.ticket_user_name}</p>
630
- <p><span class="text-opacity-70 text-white">Ticket:</span> ${submission.ticket_number}</p>
631
- <p><span class="text-opacity-70 text-white">Amount:</span> ₹${submission.amount}</p>
632
- </div>
633
- ${submission.proof_video_url ? `
634
- <button onclick="showVideoModal('${submission.proof_video_url}')" class="mt-4 text-blue-400 hover:text-blue-300 text-sm font-medium transition-all">
635
- <i class="fas fa-play-circle mr-2"></i>View Proof Video
636
- </button>
637
- ` : ''}
638
- `;
639
- list.appendChild(card);
640
- });
641
- } catch (error) {
642
- console.error('Error:', error);
643
- alert('Failed to load submissions. Please try again.');
644
- clearSession();
645
- }
646
- }
647
-
648
- function showVideoModal(url) {
649
- document.getElementById('modalVideo').src = url;
650
- document.getElementById('videoModal').classList.remove('hidden');
651
- }
652
-
653
- function closeVideoModal() {
654
- const video = document.getElementById('modalVideo');
655
- video.pause();
656
- video.src = '';
657
- document.getElementById('videoModal').classList.add('hidden');
658
- }
659
-
660
- function toggleChat() {
661
- const chat = document.getElementById('chatSection');
662
- if (chat.classList.contains('hidden')) {
663
- chat.classList.remove('hidden');
664
- loadMessages();
665
- // Join chat room for real-time updates
666
- if (eventSource && userId && userEmail) {
667
- eventSource.addEventListener('message', handleEvent);
668
- }
669
- } else {
670
- chat.classList.add('hidden');
671
- // Leave chat room
672
- if (eventSource && userId) {
673
- eventSource.close();
674
- eventSource = null;
675
- }
676
- }
677
- }
678
-
679
- async function loadMessages() {
680
- if (!userId || !userEmail || !currentOtp) return;
681
- try {
682
- const response = await fetch(`/api/messages/${userId}?limit=50`, {
683
- headers: { 'x-otp-token': currentOtp, 'x-user-email': userEmail }
684
- });
685
- const data = await response.json();
686
- if (!data.success) throw new Error(data.error);
687
-
688
- const container = document.getElementById('chatMessages');
689
- container.innerHTML = '';
690
- data.messages.forEach(msg => {
691
- const div = document.createElement('div');
692
- div.className = `flex ${msg.sender === 'user' ? 'justify-end' : 'justify-start'}`;
693
- div.innerHTML = `
694
- <div class="max-w-[80%] ${msg.sender === 'user' ? 'bg-blue-500' : 'bg-white bg-opacity-20'} rounded-2xl px-4 py-3">
695
- <p class="text-white text-sm">${msg.content}</p>
696
- <p class="text-white text-opacity-60 text-xs mt-1">${new Date(msg.created_at).toLocaleTimeString()}</p>
697
- </div>
698
- `;
699
- container.appendChild(div);
700
- });
701
- container.scrollTop = container.scrollHeight;
702
- } catch (error) {
703
- console.error('Error loading messages:', error);
704
- }
705
- }
706
-
707
- async function sendMessage() {
708
- const input = document.getElementById('messageInput');
709
- const content = input.value.trim();
710
- if (!content || !userId) return;
711
-
712
- try {
713
- const response = await fetch('/api/messages', {
714
- method: 'POST',
715
- headers: { 'Content-Type': 'application/json', 'x-otp-token': currentOtp, 'x-user-email': userEmail },
716
- body: JSON.stringify({ userId, content, sender: 'user' })
717
- });
718
- const data = await response.json();
719
- if (data.success) {
720
- input.value = '';
721
- // Message will be added via EventSource event
722
- } else throw new Error(data.error);
723
- } catch (error) {
724
- console.error('Error:', error);
725
- alert('Failed to send message');
726
- }
727
- }
728
-
729
- // Event listeners
730
- document.getElementById('messageInput')?.addEventListener('keypress', e => {
731
- if (e.key === 'Enter') sendMessage();
732
- });
733
-
734
- document.getElementById('videoModal').addEventListener('click', e => {
735
- if (e.target === document.getElementById('videoModal')) closeVideoModal();
736
- });
737
-
738
- // Ensure login menu is hidden by default
739
- document.getElementById('authSection').classList.add('hidden');
740
- // Bind the Track Status button to show login menu
741
- document.getElementById('trackStatusBtn').addEventListener('click', function() {
742
- document.getElementById('mainMenuContent').classList.add('hidden');
743
- document.getElementById('authSection').classList.remove('hidden');
744
- document.getElementById('email').focus();
745
- });
746
- </script>
747
- </body>
748
- </html>