-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.html
More file actions
855 lines (726 loc) · 34.5 KB
/
dashboard.html
File metadata and controls
855 lines (726 loc) · 34.5 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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - RedSwitch</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
--bg: #0a0a0a;
--card: #141414;
--border: #262626;
--text: #ffffff;
--text-muted: #888888;
--red: #dc2626;
--green: #10b981;
}
body {
font-family: 'Inter', sans-serif;
background: var(--bg);
color: var(--text);
min-height: 100vh;
padding: 2rem;
}
.container {
max-width: 800px;
margin: 0 auto;
}
.header {
text-align: center;
margin-bottom: 2rem;
}
.header h1 {
font-size: 2rem;
margin-bottom: 0.5rem;
}
.header p {
color: var(--text-muted);
}
.card {
background: var(--card);
border: 1px solid var(--border);
border-radius: 12px;
padding: 2rem;
margin-bottom: 1.5rem;
}
.card h2 {
font-size: 1.25rem;
margin-bottom: 1rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.form-group {
margin-bottom: 1.5rem;
}
.form-group label {
display: block;
font-weight: 500;
margin-bottom: 0.5rem;
}
.form-group .hint {
font-size: 0.85rem;
color: var(--text-muted);
margin-bottom: 0.5rem;
}
.form-group input,
.form-group textarea,
.form-group select {
width: 100%;
padding: 0.75rem 1rem;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 8px;
color: var(--text);
font-size: 1rem;
font-family: inherit;
}
.form-group input:focus,
.form-group textarea:focus {
outline: none;
border-color: var(--red);
}
.form-group textarea {
min-height: 100px;
resize: vertical;
}
.form-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
}
@media (max-width: 600px) {
.form-row { grid-template-columns: 1fr; }
}
.btn {
display: inline-block;
padding: 0.75rem 1.5rem;
border-radius: 8px;
font-weight: 500;
font-size: 1rem;
cursor: pointer;
border: none;
transition: all 0.2s;
}
.btn-primary {
background: var(--red);
color: white;
}
.btn-primary:hover {
background: #b91c1c;
}
.btn-secondary {
background: transparent;
border: 1px solid var(--border);
color: var(--text);
}
.status {
display: inline-flex;
align-items: center;
gap: 0.5rem;
padding: 0.25rem 0.75rem;
border-radius: 999px;
font-size: 0.85rem;
font-weight: 500;
}
.status.active {
background: rgba(16, 185, 129, 0.2);
color: var(--green);
}
.status.shutdown {
background: rgba(99, 102, 241, 0.2);
color: #6366f1;
}
.agent-info {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem;
background: var(--bg);
border-radius: 8px;
margin-bottom: 1rem;
}
.agent-info .name {
font-weight: 600;
font-size: 1.1rem;
}
.agent-info .meta {
color: var(--text-muted);
font-size: 0.85rem;
}
.emergency-contact {
background: var(--bg);
border-radius: 8px;
padding: 1rem;
margin-bottom: 1rem;
}
.emergency-contact .contact-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 0.75rem;
}
.emergency-contact .contact-number {
font-weight: 600;
color: var(--text-muted);
}
.remove-btn {
background: none;
border: none;
color: var(--red);
cursor: pointer;
font-size: 0.85rem;
}
.add-btn {
width: 100%;
padding: 0.75rem;
background: transparent;
border: 1px dashed var(--border);
border-radius: 8px;
color: var(--text-muted);
cursor: pointer;
font-size: 0.9rem;
}
.add-btn:hover {
border-color: var(--red);
color: var(--red);
}
/* Login screen */
#login-screen {
max-width: 400px;
margin: 4rem auto;
}
#login-screen .card {
text-align: center;
}
#login-screen h1 {
margin-bottom: 0.5rem;
}
#login-screen p {
color: var(--text-muted);
margin-bottom: 2rem;
}
#login-screen .form-group {
text-align: left;
}
#dashboard-screen {
display: none;
}
.message {
padding: 1rem;
border-radius: 8px;
margin-bottom: 1rem;
display: none;
}
.message.success {
background: rgba(16, 185, 129, 0.2);
color: var(--green);
display: block;
}
.message.error {
background: rgba(220, 38, 38, 0.2);
color: var(--red);
display: block;
}
.example {
background: var(--bg);
border-left: 3px solid var(--red);
padding: 0.75rem 1rem;
margin-top: 0.5rem;
font-size: 0.85rem;
color: var(--text-muted);
}
.back-link {
display: inline-flex;
align-items: center;
gap: 0.5rem;
color: var(--text-muted);
text-decoration: none;
margin-bottom: 1rem;
}
.back-link:hover {
color: var(--text);
}
</style>
</head>
<body>
<!-- Login Screen -->
<div id="login-screen">
<div class="card">
<h1><img src="/images/toggle-icon.png" alt="" style="height: 96px; width: auto; vertical-align: middle; margin-right: 0;">RedSwitch</h1>
<p>Enter your agent credentials to access the dashboard</p>
<div id="login-message" class="message"></div>
<div class="form-group">
<label>Registration ID</label>
<div class="hint">Found in your registration response (starts with rs_)</div>
<input type="text" id="login-reg-id" placeholder="rs_7edef619a8da63e9">
</div>
<div class="form-group">
<label>PIN</label>
<div class="hint">4-6 digits. New agents: enter any PIN to set it. Returning: enter your existing PIN.</div>
<input type="password" id="login-pin" placeholder="----" maxlength="6" pattern="[0-9]*" inputmode="numeric">
</div>
<button class="btn btn-primary" style="width: 100%;" onclick="login()">Access Dashboard</button>
<div style="margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); text-align: center;">
<p style="color: var(--text-muted); margin-bottom: 1rem;">Don't have an agent yet?</p>
<button class="btn btn-secondary" style="width: 100%;" onclick="showRegister()">Register New Agent</button>
</div>
</div>
</div>
<!-- Register Screen -->
<div id="register-screen" style="display: none;">
<div class="card" style="max-width: 500px; margin: 4rem auto;">
<h1 style="text-align: center; margin-bottom: 0.5rem;">🔴 Register Agent</h1>
<p style="text-align: center; color: var(--text-muted); margin-bottom: 2rem;">Create a new RedSwitch agent in seconds</p>
<div id="register-message" class="message"></div>
<!-- Registration Success (hidden by default) -->
<div id="register-success" style="display: none;">
<div style="text-align: center; padding: 2rem 0;">
<div style="font-size: 4rem; margin-bottom: 1rem;">✅</div>
<h2 style="color: var(--green); margin-bottom: 1rem;">Agent Registered!</h2>
<p style="color: var(--text-muted); margin-bottom: 1.5rem;">Save your Registration ID - you'll need it to access the dashboard.</p>
</div>
<div class="form-group">
<label>Your Registration ID</label>
<div style="display: flex; gap: 0.5rem;">
<input type="text" id="new-reg-id" readonly style="font-family: monospace; font-size: 1rem;">
<button class="btn btn-primary" onclick="copyRegId()" id="copy-btn" style="white-space: nowrap;">📋 Copy</button>
</div>
<div class="hint" style="margin-top: 0.5rem; color: var(--red);">⚠️ Save this somewhere safe! You cannot recover it.</div>
</div>
<div style="margin-top: 2rem;">
<button class="btn btn-primary" style="width: 100%;" onclick="goToLoginWithId()">Continue to Dashboard →</button>
</div>
</div>
<!-- Registration Form -->
<div id="register-form">
<div class="form-group">
<label>Agent Name</label>
<div class="hint">A friendly name for your agent</div>
<input type="text" id="reg-agent-name" placeholder="My AI Assistant">
</div>
<div class="form-group">
<label>Your Email</label>
<div class="hint">For notifications when your agent needs attention</div>
<input type="email" id="reg-email" placeholder="you@example.com">
</div>
<button class="btn btn-primary" style="width: 100%; margin-top: 1rem;" onclick="registerAgent()">Register Agent</button>
<div style="text-align: center; margin-top: 1.5rem;">
<a href="#" onclick="showLogin(); return false;" style="color: var(--text-muted);">← Back to Login</a>
</div>
</div>
</div>
</div>
<!-- Dashboard Screen -->
<div id="dashboard-screen" class="container">
<a href="https://redswitch.ai" class="back-link">← Back to RedSwitch</a>
<div class="header">
<h1>Agent Dashboard</h1>
<p>Configure your agent's failsafe settings</p>
</div>
<div id="dashboard-message" class="message"></div>
<!-- Agent Status -->
<div class="card">
<h2>📊 Agent Status</h2>
<div class="agent-info">
<div>
<div class="name" id="agent-name">Loading...</div>
<div class="meta">Last heartbeat: <span id="last-heartbeat">-</span></div>
</div>
<span class="status active" id="agent-status">Active</span>
</div>
</div>
<!-- Timeout Settings -->
<div class="card">
<h2>⏱️ Timeout Settings</h2>
<div class="form-row">
<div class="form-group">
<label>Timeout Period</label>
<div class="hint">How long before we start worrying</div>
<select id="timeout-hours">
<option value="24">24 hours (1 day)</option>
<option value="48">48 hours (2 days)</option>
<option value="72" selected>72 hours (3 days)</option>
<option value="168">168 hours (1 week)</option>
<option value="336">336 hours (2 weeks)</option>
<option value="720">720 hours (30 days)</option>
<option value="2160">2160 hours (90 days)</option>
<option value="8760">8760 hours (1 year)</option>
</select>
</div>
<div class="form-group">
<label>Grace Period</label>
<div class="hint">Extra time after warning before shutdown</div>
<select id="grace-period">
<option value="12">12 hours</option>
<option value="24" selected>24 hours (1 day)</option>
<option value="48">48 hours (2 days)</option>
<option value="72">72 hours (3 days)</option>
<option value="168">168 hours (1 week)</option>
<option value="336">336 hours (2 weeks)</option>
</select>
</div>
</div>
<div class="form-group">
<label>
<input type="checkbox" id="vacation-mode"> Vacation Mode
</label>
<div class="hint">Pause monitoring temporarily. Resets on next heartbeat.</div>
</div>
</div>
<!-- Notifications -->
<div class="card">
<h2>🔔 Notifications</h2>
<div class="form-row">
<div class="form-group">
<label>Email</label>
<input type="email" id="notification-email" placeholder="you@example.com">
</div>
<div class="form-group">
<label>Telegram Chat ID</label>
<div class="hint">Message @RedSwitchBot to get your ID</div>
<input type="text" id="telegram-chat-id" placeholder="123456789">
</div>
</div>
<div class="form-group" style="margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border);">
<label>🧪 Test Your Notifications</label>
<div class="hint" style="margin-bottom: 0.75rem;">Send a test alert to verify your email and Telegram are configured correctly.</div>
<div style="background: #1a1a00; border: 1px solid #665500; border-radius: 6px; padding: 0.75rem; margin-bottom: 0.75rem; font-size: 0.875rem;">
⚠️ <strong>Check your spam folder!</strong> RedSwitch emails may land in spam until you mark them as "not spam."
</div>
<button onclick="sendTestNotification()" id="test-notification-btn" style="background: var(--border); padding: 0.75rem 1.5rem; border: none; border-radius: 6px; color: var(--text); cursor: pointer; font-weight: 500;">
📧 Send Test Alert
</button>
<div id="test-notification-result" style="margin-top: 0.75rem; font-size: 0.875rem;"></div>
</div>
</div>
<!-- Emergency Contacts (Legacy Only) -->
<div class="card">
<h2>🚨 Emergency Contacts <span style="color: var(--red); font-size: 0.75rem; font-weight: normal;">(Legacy Plan)</span></h2>
<div class="hint" style="margin-bottom: 1rem;">These people will be notified if you can't respond. They'll receive a plain-English explanation.</div>
<div id="emergency-contacts">
<!-- Contacts added dynamically -->
</div>
<button class="add-btn" onclick="addEmergencyContact()" id="add-contact-btn">+ Add Emergency Contact (up to 3)</button>
</div>
<!-- Estate Report -->
<div class="card">
<h2>📋 Estate Report <span style="color: var(--red); font-size: 0.75rem; font-weight: normal;">(Legacy Plan)</span></h2>
<div class="hint" style="margin-bottom: 1rem;">This information helps your emergency contacts understand what this agent was and how to handle it.</div>
<div class="form-group">
<label>What is this agent?</label>
<div class="hint">Describe what this AI does in plain English</div>
<textarea id="estate-description" placeholder="My personal AI assistant that helps manage my calendar and emails..."></textarea>
<div class="example">💡 Example: "This is an AI assistant I built to help manage my small business. It monitors my email, responds to customer inquiries, and schedules appointments."</div>
</div>
<div class="form-group">
<label>Connected Services</label>
<div class="hint">What accounts/APIs does this agent have access to?</div>
<textarea id="estate-services" placeholder="OpenAI API Gmail Google Calendar Notion"></textarea>
<div class="example">💡 List each service on a new line. Include anything that costs money or has sensitive access.</div>
</div>
<div class="form-group">
<label>Estimated Monthly Cost</label>
<div class="hint">Approximate cost to run this agent per month</div>
<input type="text" id="estate-cost" placeholder="$50/month">
</div>
<div class="form-group">
<label>Cleanup Instructions</label>
<div class="hint">Step-by-step instructions for shutting everything down</div>
<textarea id="estate-cleanup" placeholder="1. Go to platform.openai.com and cancel the subscription 2. Revoke API keys in Settings > API Keys 3. ..."></textarea>
<div class="example">💡 Write this for someone who may not be technical. Include URLs and specific steps.</div>
</div>
<div class="form-group">
<label>Additional Notes</label>
<div class="hint">Anything else your emergency contacts should know</div>
<textarea id="estate-notes" placeholder="My brother Jake is technical and can help with this. His number is..."></textarea>
</div>
</div>
<!-- Save Button -->
<div style="text-align: center; margin-top: 2rem;">
<button class="btn btn-primary" style="padding: 1rem 3rem; font-size: 1.1rem;" onclick="saveConfig()">Save Configuration</button>
</div>
</div>
<script>
const API_BASE = 'https://api.redswitch.ai';
let currentRegId = '';
let currentPin = '';
let emergencyContacts = [];
async function login() {
const regId = document.getElementById('login-reg-id').value.trim();
const pin = document.getElementById('login-pin').value.trim();
const messageEl = document.getElementById('login-message');
if (!regId || !pin) {
messageEl.className = 'message error';
messageEl.textContent = 'Please enter both Registration ID and PIN';
return;
}
if (pin.length < 4 || !/^\d+$/.test(pin)) {
messageEl.className = 'message error';
messageEl.textContent = 'PIN must be 4-6 digits';
return;
}
try {
const response = await fetch(`${API_BASE}/v1/dashboard/auth`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ registration_id: regId, pin: pin })
});
const data = await response.json();
if (data.success) {
currentRegId = regId;
currentPin = pin;
showDashboard(data);
} else {
messageEl.className = 'message error';
messageEl.textContent = data.error || 'Login failed';
}
} catch (e) {
messageEl.className = 'message error';
messageEl.textContent = 'Connection error. Please try again.';
}
}
function showDashboard(data) {
document.getElementById('login-screen').style.display = 'none';
document.getElementById('dashboard-screen').style.display = 'block';
// Populate agent info
document.getElementById('agent-name').textContent = data.agent.agent_name || data.agent.agent_id;
document.getElementById('last-heartbeat').textContent = new Date(data.agent.last_heartbeat).toLocaleString();
const statusEl = document.getElementById('agent-status');
statusEl.textContent = data.agent.status.charAt(0).toUpperCase() + data.agent.status.slice(1);
statusEl.className = 'status ' + data.agent.status;
// Populate config
const config = data.config || {};
if (config.timeout_hours) {
document.getElementById('timeout-hours').value = config.timeout_hours;
}
if (config.grace_period_hours) {
document.getElementById('grace-period').value = config.grace_period_hours;
}
if (config.vacation_mode) {
document.getElementById('vacation-mode').checked = config.vacation_mode;
}
if (config.notification_email) {
document.getElementById('notification-email').value = config.notification_email;
}
if (config.telegram_chat_id) {
document.getElementById('telegram-chat-id').value = config.telegram_chat_id;
}
// Estate report
if (config.estate_report) {
const er = config.estate_report;
if (er.description) document.getElementById('estate-description').value = er.description;
if (er.services) document.getElementById('estate-services').value = er.services;
if (er.cost) document.getElementById('estate-cost').value = er.cost;
if (er.cleanup) document.getElementById('estate-cleanup').value = er.cleanup;
if (er.notes) document.getElementById('estate-notes').value = er.notes;
}
// Emergency contacts
emergencyContacts = config.emergency_contacts || [];
renderEmergencyContacts();
}
function renderEmergencyContacts() {
const container = document.getElementById('emergency-contacts');
container.innerHTML = '';
emergencyContacts.forEach((contact, index) => {
const div = document.createElement('div');
div.className = 'emergency-contact';
div.innerHTML = `
<div class="contact-header">
<span class="contact-number">Contact ${index + 1}</span>
<button class="remove-btn" onclick="removeEmergencyContact(${index})">Remove</button>
</div>
<div class="form-row">
<div class="form-group" style="margin-bottom: 0.5rem;">
<input type="text" placeholder="Name" value="${contact.name || ''}" onchange="updateContact(${index}, 'name', this.value)">
</div>
<div class="form-group" style="margin-bottom: 0.5rem;">
<input type="email" placeholder="Email" value="${contact.email || ''}" onchange="updateContact(${index}, 'email', this.value)">
</div>
</div>
<div class="form-group" style="margin-bottom: 0;">
<input type="text" placeholder="Relationship (e.g., spouse, brother, business partner)" value="${contact.relationship || ''}" onchange="updateContact(${index}, 'relationship', this.value)">
</div>
`;
container.appendChild(div);
});
// Show/hide add button
document.getElementById('add-contact-btn').style.display = emergencyContacts.length >= 3 ? 'none' : 'block';
}
function addEmergencyContact() {
if (emergencyContacts.length >= 3) return;
emergencyContacts.push({ name: '', email: '', relationship: '' });
renderEmergencyContacts();
}
function removeEmergencyContact(index) {
emergencyContacts.splice(index, 1);
renderEmergencyContacts();
}
function updateContact(index, field, value) {
emergencyContacts[index][field] = value;
}
async function sendTestNotification() {
const btn = document.getElementById('test-notification-btn');
const resultEl = document.getElementById('test-notification-result');
btn.disabled = true;
btn.textContent = '⏳ Sending...';
resultEl.innerHTML = '';
try {
const response = await fetch(`${API_URL}/v1/test/notify`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
registration_id: currentRegistrationId,
type: 'warning'
})
});
const data = await response.json();
if (data.success) {
const results = [];
if (data.results?.email?.success) results.push('✅ Email sent');
else if (data.results?.email?.error) results.push('❌ Email: ' + data.results.email.error);
else if (!document.getElementById('notification-email').value) results.push('⚠️ No email configured');
if (data.results?.telegram?.success) results.push('✅ Telegram sent');
else if (data.results?.telegram?.error) results.push('❌ Telegram: ' + data.results.telegram.error);
else if (!document.getElementById('telegram-chat-id').value) results.push('⚠️ No Telegram configured');
resultEl.innerHTML = results.length ? results.join('<br>') : '⚠️ No notifications configured';
resultEl.style.color = results.some(r => r.startsWith('✅')) ? 'var(--green)' : 'var(--text-muted)';
} else {
resultEl.innerHTML = '❌ ' + (data.error || 'Failed to send test');
resultEl.style.color = 'var(--red)';
}
} catch (error) {
resultEl.innerHTML = '❌ Network error: ' + error.message;
resultEl.style.color = 'var(--red)';
}
btn.disabled = false;
btn.textContent = '📧 Send Test Alert';
}
async function saveConfig() {
const messageEl = document.getElementById('dashboard-message');
const updates = {
timeout_hours: parseInt(document.getElementById('timeout-hours').value),
grace_period_hours: parseInt(document.getElementById('grace-period').value),
vacation_mode: document.getElementById('vacation-mode').checked,
notification_email: document.getElementById('notification-email').value.trim(),
telegram_chat_id: document.getElementById('telegram-chat-id').value.trim(),
emergency_contacts: emergencyContacts.filter(c => c.name && c.email),
estate_report: {
description: document.getElementById('estate-description').value.trim(),
services: document.getElementById('estate-services').value.trim(),
cost: document.getElementById('estate-cost').value.trim(),
cleanup: document.getElementById('estate-cleanup').value.trim(),
notes: document.getElementById('estate-notes').value.trim()
}
};
try {
const response = await fetch(`${API_BASE}/v1/dashboard/save`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
registration_id: currentRegId,
pin: currentPin,
updates: updates
})
});
const data = await response.json();
if (data.success) {
messageEl.className = 'message success';
messageEl.textContent = '✓ Configuration saved successfully!';
window.scrollTo({ top: 0, behavior: 'smooth' });
} else {
messageEl.className = 'message error';
messageEl.textContent = data.error || 'Save failed';
}
} catch (e) {
messageEl.className = 'message error';
messageEl.textContent = 'Connection error. Please try again.';
}
// Clear message after 5 seconds
setTimeout(() => {
messageEl.className = 'message';
}, 5000);
}
// Handle Enter key on login
document.getElementById('login-pin').addEventListener('keypress', (e) => {
if (e.key === 'Enter') login();
});
document.getElementById('login-reg-id').addEventListener('keypress', (e) => {
if (e.key === 'Enter') document.getElementById('login-pin').focus();
});
// Registration functions
function showRegister() {
document.getElementById('login-screen').style.display = 'none';
document.getElementById('register-screen').style.display = 'block';
document.getElementById('register-form').style.display = 'block';
document.getElementById('register-success').style.display = 'none';
}
function showLogin() {
document.getElementById('register-screen').style.display = 'none';
document.getElementById('login-screen').style.display = 'block';
}
let newRegistrationId = '';
async function registerAgent() {
const name = document.getElementById('reg-agent-name').value.trim();
const email = document.getElementById('reg-email').value.trim();
const messageEl = document.getElementById('register-message');
if (!name) {
messageEl.className = 'message error';
messageEl.textContent = 'Please enter an agent name';
return;
}
if (!email || !email.includes('@')) {
messageEl.className = 'message error';
messageEl.textContent = 'Please enter a valid email address';
return;
}
messageEl.className = 'message';
try {
const response = await fetch(`${API_BASE}/v1/agents/register`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
agent_id: name.toLowerCase().replace(/[^a-z0-9]/g, '-'),
agent_name: name,
human_id: email
})
});
const data = await response.json();
if (data.success) {
newRegistrationId = data.registration_id;
document.getElementById('new-reg-id').value = newRegistrationId;
document.getElementById('register-form').style.display = 'none';
document.getElementById('register-success').style.display = 'block';
} else {
messageEl.className = 'message error';
messageEl.textContent = data.error || 'Registration failed';
}
} catch (e) {
messageEl.className = 'message error';
messageEl.textContent = 'Connection error. Please try again.';
}
}
function copyRegId() {
const input = document.getElementById('new-reg-id');
input.select();
document.execCommand('copy');
const btn = document.getElementById('copy-btn');
btn.textContent = '✓ Copied!';
btn.style.background = 'var(--green)';
setTimeout(() => {
btn.textContent = '📋 Copy';
btn.style.background = '';
}, 2000);
}
function goToLoginWithId() {
document.getElementById('register-screen').style.display = 'none';
document.getElementById('login-screen').style.display = 'block';
document.getElementById('login-reg-id').value = newRegistrationId;
document.getElementById('login-pin').focus();
}
</script>
</body>
</html>