Repository navigation
Expand file tree
/
Copy pathsettings.html
More file actions
1075 lines (968 loc) · 47.9 KB
/
Copy pathsettings.html
File metadata and controls
1075 lines (968 loc) · 47.9 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
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PDRides - Settings</title>
<!-- External CSS -->
<link rel="stylesheet" href="/css/settings.css">
</head>
<body>
<div class="background-wrapper">
<div class="container">
<!-- Header -->
<div class="header">
<div class="header-left">
<a href="/map" class="back-btn">←</a>
<h1>Settings</h1>
</div>
<div class="role-toggle">
<button class="role-btn" id="passengerModeBtn" onclick="setUserMode('passenger')">👤</button>
<button class="role-btn" id="driverModeBtn" onclick="setUserMode('driver')">🚙</button>
</div>
</div>
<!-- Profile Card -->
<div class="profile-card">
<div class="profile-avatar-container">
<div class="profile-avatar" id="profileAvatar">U</div>
<label class="profile-avatar-edit" for="profilePhotoInput">
📷
<input type="file" id="profilePhotoInput" accept="image/*" onchange="handleProfilePhotoUpload(event)">
</label>
</div>
<div class="profile-name" id="profileName">User</div>
<div class="profile-phone" id="profilePhone">+1 555 123 4567</div>
<span class="profile-badge" id="profileBadge">Passenger</span>
</div>
<!-- Account Section -->
<div class="section-card">
<div class="section-header">Account</div>
<div class="menu-item" onclick="showEditProfileModal();">
<div class="menu-item-left">
<div class="menu-icon">✏️</div>
<div class="menu-text">
<h3>Edit Profile</h3>
<p>Name, email, emergency contact</p>
</div>
</div>
<span class="menu-arrow">›</span>
</div>
<div class="menu-item" onclick="showChangePasswordModal();">
<div class="menu-item-left">
<div class="menu-icon">🔑</div>
<div class="menu-text">
<h3>Change Password</h3>
<p>Update your password</p>
</div>
</div>
<span class="menu-arrow">›</span>
</div>
<div class="menu-item" onclick="showNotificationSettings();">
<div class="menu-item-left">
<div class="menu-icon">🔔</div>
<div class="menu-text">
<h3>Notifications</h3>
<p>Push, email, SMS preferences</p>
</div>
</div>
<span class="menu-arrow">›</span>
</div>
<div class="menu-item" onclick="showPrivacySettings();">
<div class="menu-item-left">
<div class="menu-icon">🔒</div>
<div class="menu-text">
<h3>Privacy</h3>
<p>Profile visibility settings</p>
</div>
</div>
<span class="menu-arrow">›</span>
</div>
</div>
<!-- Driver Section -->
<div class="section-card" id="driverSettingsCard">
<div class="section-header">Driver</div>
<div class="menu-item" onclick="showVehicleInfoModal();">
<div class="menu-item-left">
<div class="menu-icon">🚗</div>
<div class="menu-text">
<h3>Vehicle Information</h3>
<p>Make, model, license plate</p>
</div>
</div>
<span class="menu-arrow">›</span>
</div>
<div class="menu-item" onclick="showDriverPreferencesModal();">
<div class="menu-item-left">
<div class="menu-icon">⚙️</div>
<div class="menu-text">
<h3>Driving Preferences</h3>
<p>Smoking, music, pets, etc.</p>
</div>
</div>
<span class="menu-arrow">›</span>
</div>
</div>
<!-- Data & Privacy Section -->
<div class="section-card">
<div class="section-header">Data & Privacy</div>
<div class="menu-item" onclick="downloadData();">
<div class="menu-item-left">
<div class="menu-icon">📥</div>
<div class="menu-text">
<h3>Download My Data</h3>
<p>Get a copy of your data</p>
</div>
</div>
<span class="menu-arrow">›</span>
</div>
<div class="menu-item danger" onclick="showDeleteAccountModal();">
<div class="menu-item-left">
<div class="menu-icon">🗑️</div>
<div class="menu-text">
<h3>Delete Account</h3>
<p>Permanently delete account</p>
</div>
</div>
<span class="menu-arrow">›</span>
</div>
</div>
<!-- Support Section -->
<div class="section-card">
<div class="section-header">Support</div>
<a href="/help-center" class="menu-item">
<div class="menu-item-left">
<div class="menu-icon">❓</div>
<div class="menu-text">
<h3>Help Center</h3>
<p>FAQs and support</p>
</div>
</div>
<span class="menu-arrow">›</span>
</a>
<div class="menu-item" onclick="contactForBusiness();">
<div class="menu-item-left">
<div class="menu-icon">📧</div>
<div class="menu-text">
<h3>Contact Us for Business</h3>
<p>Promote your local business</p>
</div>
</div>
<span class="menu-arrow">›</span>
</div>
<a href="#" class="menu-item" id="termsPrivacyLink" onclick="showTermsPrivacy(); return false;">
<div class="menu-item-left">
<div class="menu-icon">📜</div>
<div class="menu-text">
<h3>Terms & Privacy</h3>
<p>Legal documents</p>
</div>
</div>
<span class="menu-arrow">›</span>
</a>
<div class="menu-item danger" onclick="logout();">
<div class="menu-item-left">
<div class="menu-icon">🚪</div>
<div class="menu-text">
<h3>Logout</h3>
<p>Sign out of your account</p>
</div>
</div>
<span class="menu-arrow">›</span>
</div>
</div>
<div class="version">PDRides v1.0.0 • © 2025</div>
</div>
</div>
<!-- Edit Profile Modal -->
<div class="modal-overlay" id="editProfileModal">
<div class="modal-content">
<div class="modal-header info">
<h2>✏️ Edit Profile</h2>
<p>Update your personal information</p>
<button class="modal-close" onclick="closeModal('editProfileModal')">×</button>
</div>
<div class="modal-body">
<div class="form-group">
<label>Full Name</label>
<input type="text" id="profileNameInput" placeholder="Enter your full name">
</div>
<div class="form-group">
<label>Email Address</label>
<input type="email" id="profileEmailInput" placeholder="Enter your email">
</div>
<div class="form-group">
<label>Emergency Contact Name</label>
<input type="text" id="emergencyContactName" placeholder="Emergency contact name">
</div>
<div class="form-group">
<label>Emergency Contact Phone</label>
<input type="tel" id="emergencyContactPhone" placeholder="Emergency contact phone">
</div>
<div class="btn-row">
<button class="btn btn-secondary" onclick="closeModal('editProfileModal')">Cancel</button>
<button class="btn btn-primary" id="saveProfileBtn" onclick="saveProfile()">Save Changes</button>
</div>
</div>
</div>
</div>
<!-- Change Password Modal -->
<div class="modal-overlay" id="changePasswordModal">
<div class="modal-content">
<div class="modal-header info">
<h2>🔑 Change Password</h2>
<p>Update your account password</p>
<button class="modal-close" onclick="closeModal('changePasswordModal')">×</button>
</div>
<div class="modal-body">
<div class="form-group">
<label>Current Password</label>
<input type="password" id="currentPassword" placeholder="Enter current password">
</div>
<div class="form-group">
<label>New Password</label>
<input type="password" id="newPassword" placeholder="Enter new password">
</div>
<div class="form-group">
<label>Confirm New Password</label>
<input type="password" id="confirmNewPassword" placeholder="Confirm new password">
</div>
<div class="btn-row">
<button class="btn btn-secondary" onclick="closeModal('changePasswordModal')">Cancel</button>
<button class="btn btn-primary" onclick="changePassword()">Update Password</button>
</div>
</div>
</div>
</div>
<!-- Notification Settings Modal -->
<div class="modal-overlay" id="notificationSettingsModal">
<div class="modal-content">
<div class="modal-header info">
<h2>🔔 Notification Settings</h2>
<p>Manage your notification preferences</p>
<button class="modal-close" onclick="closeModal('notificationSettingsModal')">×</button>
</div>
<div class="modal-body">
<div class="checkbox-item">
<input type="checkbox" id="pushNotifications" checked>
<div class="checkbox-item-text">
<h4>Push Notifications</h4>
<p>Receive push notifications on your device</p>
</div>
</div>
<div class="checkbox-item">
<input type="checkbox" id="emailNotifications" checked>
<div class="checkbox-item-text">
<h4>Email Notifications</h4>
<p>Receive updates via email</p>
</div>
</div>
<div class="checkbox-item">
<input type="checkbox" id="smsNotifications" checked>
<div class="checkbox-item-text">
<h4>SMS Notifications</h4>
<p>Receive important updates via SMS</p>
</div>
</div>
<div class="checkbox-item">
<input type="checkbox" id="rideAlerts" checked>
<div class="checkbox-item-text">
<h4>Ride Alerts</h4>
<p>Get notified about ride requests and updates</p>
</div>
</div>
<div class="checkbox-item">
<input type="checkbox" id="promotionalEmails">
<div class="checkbox-item-text">
<h4>Promotional Emails</h4>
<p>Receive promotional offers and discounts</p>
</div>
</div>
<div class="btn-row">
<button class="btn btn-primary" onclick="saveNotificationSettings()">Save Preferences</button>
</div>
</div>
</div>
</div>
<!-- Privacy Settings Modal -->
<div class="modal-overlay" id="privacySettingsModal">
<div class="modal-content">
<div class="modal-header info">
<h2>🔒 Privacy Settings</h2>
<p>Control your profile visibility</p>
<button class="modal-close" onclick="closeModal('privacySettingsModal')">×</button>
</div>
<div class="modal-body">
<div class="checkbox-item">
<input type="checkbox" id="profileVisibility" checked>
<div class="checkbox-item-text">
<h4>Profile Visibility</h4>
<p>Allow other users to see your profile</p>
</div>
</div>
<div class="checkbox-item">
<input type="checkbox" id="showOnlineStatus" checked>
<div class="checkbox-item-text">
<h4>Online Status</h4>
<p>Show when you're online to other users</p>
</div>
</div>
<div class="checkbox-item">
<input type="checkbox" id="shareRideHistory">
<div class="checkbox-item-text">
<h4>Share Ride History</h4>
<p>Allow others to view your ride history</p>
</div>
</div>
<div class="checkbox-item">
<input type="checkbox" id="locationTracking" checked>
<div class="checkbox-item-text">
<h4>Location Tracking</h4>
<p>Allow app to access your location</p>
</div>
</div>
<div class="btn-row">
<button class="btn btn-primary" onclick="savePrivacySettings()">Save Settings</button>
</div>
</div>
</div>
</div>
<!-- Vehicle Info Modal -->
<div class="modal-overlay" id="vehicleInfoModal">
<div class="modal-content">
<div class="modal-header info">
<h2>🚗 Vehicle Information</h2>
<p>Update your vehicle details</p>
<button class="modal-close" onclick="closeModal('vehicleInfoModal')">×</button>
</div>
<div class="modal-body">
<div class="form-group">
<label>Vehicle Make</label>
<input type="text" id="vehicleMake" placeholder="e.g., Toyota">
</div>
<div class="form-group">
<label>Vehicle Model</label>
<input type="text" id="vehicleModel" placeholder="e.g., Camry">
</div>
<div class="form-row">
<div class="form-group">
<label>Year</label>
<input type="text" id="vehicleYear" placeholder="e.g., 2022">
</div>
<div class="form-group">
<label>Color</label>
<input type="text" id="vehicleColor" placeholder="e.g., Silver">
</div>
</div>
<div class="form-group">
<label>License Plate</label>
<input type="text" id="licensePlate" placeholder="e.g., ABC 1234">
</div>
<div class="btn-row">
<button class="btn btn-secondary" onclick="closeModal('vehicleInfoModal')">Cancel</button>
<button class="btn btn-primary" onclick="saveVehicleInfo()">Save Vehicle</button>
</div>
</div>
</div>
</div>
<!-- Driver Preferences Modal -->
<div class="modal-overlay" id="driverPreferencesModal">
<div class="modal-content">
<div class="modal-header info">
<h2>⚙️ Driving Preferences</h2>
<p>Set your driving preferences</p>
<button class="modal-close" onclick="closeModal('driverPreferencesModal')">×</button>
</div>
<div class="modal-body">
<div class="checkbox-item">
<input type="checkbox" id="allowSmoking">
<div class="checkbox-item-text">
<h4>Allow Smoking</h4>
<p>Allow passengers to smoke in the vehicle</p>
</div>
</div>
<div class="checkbox-item">
<input type="checkbox" id="allowPets">
<div class="checkbox-item-text">
<h4>Allow Pets</h4>
<p>Allow pets in the vehicle</p>
</div>
</div>
<div class="checkbox-item">
<input type="checkbox" id="allowMusic" checked>
<div class="checkbox-item-text">
<h4>Play Music</h4>
<p>Play your preferred music during rides</p>
</div>
</div>
<div class="checkbox-item">
<input type="checkbox" id="airConditioning" checked>
<div class="checkbox-item-text">
<h4>Air Conditioning</h4>
<p>Use AC during rides</p>
</div>
</div>
<div class="form-group">
<label>Additional Notes</label>
<input type="text" id="additionalNotes" placeholder="Any other preferences...">
</div>
<div class="btn-row">
<button class="btn btn-primary" onclick="saveDriverPreferences()">Save Preferences</button>
</div>
</div>
</div>
</div>
<!-- Delete Account Modal -->
<div class="modal-overlay" id="deleteAccountModal">
<div class="modal-content">
<div class="modal-header danger">
<h2>🗑️ Delete Account</h2>
<p>This action cannot be undone</p>
<button class="modal-close" onclick="closeModal('deleteAccountModal')">×</button>
</div>
<div class="modal-body">
<div class="warning-box">
<div class="warning-box-title">⚠️ Warning</div>
<p>Deleting your account will:</p>
<ul>
<li>Permanently remove all your data</li>
<li>Delete your ride history</li>
<li>Remove all saved routes and preferences</li>
<li>Cancel any active rides</li>
</ul>
</div>
<div class="form-group">
<label>Type "DELETE" to confirm</label>
<input type="text" id="deleteConfirmation" placeholder="Type DELETE">
</div>
<div class="btn-row">
<button class="btn btn-secondary" onclick="closeModal('deleteAccountModal')">Cancel</button>
<button class="btn btn-danger" onclick="deleteAccount()">Delete Account</button>
</div>
</div>
</div>
</div>
<!-- Contact Modal -->
<div class="modal-overlay" id="contactModal">
<div class="modal-content">
<div class="modal-header info">
<h2>📧 Contact Us</h2>
<p>Choose your preferred support method</p>
<button class="modal-close" onclick="closeModal('contactModal')">×</button>
</div>
<div class="modal-body">
<div class="contact-options">
<div class="contact-option" onclick="contactViaEmail();">
<div class="contact-option-icon">📧</div>
<div class="contact-option-text">
<h4>Email Support</h4>
<p>ads@pdrides.com</p>
</div>
</div>
<div class="contact-option" onclick="contactViaWhatsApp();">
<div class="contact-option-icon">💬</div>
<div class="contact-option-text">
<h4>WhatsApp</h4>
<p>Chat with us on WhatsApp</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Terms & Privacy Modal -->
<div class="modal-overlay" id="termsPrivacyModal">
<div class="modal-content">
<div class="modal-header info">
<h2>📜 Terms & Privacy</h2>
<p>Legal documents</p>
<button class="modal-close" onclick="closeModal('termsPrivacyModal')">×</button>
</div>
<div class="modal-body" style="max-height: 60vh; overflow-y: auto;">
<div style="margin-bottom: var(--space-lg);">
<h3 style="color: #333; margin-bottom: var(--space-sm); font-size: var(--font-base);">📄 Terms of Service</h3>
<div style="background: #f8f9fa; padding: var(--space-md); border-radius: clamp(8px, 2vw + 4px, 14px); font-size: var(--font-sm); color: #666; line-height: 1.6;">
<p style="margin-bottom: var(--space-sm);">By using PDRides, you agree to our terms of service:</p>
<ul style="margin-left: var(--space-md);">
<li>All users must be 18 years or older</li>
<li>Drivers must have valid license and insurance</li>
<li>Shared rides must follow local traffic laws</li>
<li>All rides are at user's own risk</li>
<li>PDRides is not liable for any damages</li>
<li>Users must treat each other with respect</li>
<li>Cancellation fees may apply</li>
</ul>
</div>
</div>
<div style="margin-bottom: var(--space-lg);">
<h3 style="color: #333; margin-bottom: var(--space-sm); font-size: var(--font-base);">🔒 Privacy Policy</h3>
<div style="background: #f8f9fa; padding: var(--space-md); border-radius: clamp(8px, 2vw + 4px, 14px); font-size: var(--font-sm); color: #666; line-height: 1.6;">
<p style="margin-bottom: var(--space-sm);">Your privacy is important to us:</p>
<ul style="margin-left: var(--space-md);">
<li>We collect only necessary personal data</li>
<li>Location data is used for ride matching</li>
<li>Phone numbers are used for authentication</li>
<li>Data is encrypted and stored securely</li>
<li>We never sell your data to third parties</li>
<li>You can request data deletion anytime</li>
<li>Trip history is kept for 2 years</li>
</ul>
</div>
</div>
<div style="text-align: center; margin-top: var(--space-md);">
<a href="/terms-of-service" style="color: #667eea; text-decoration: none; font-size: var(--font-sm);">View Full Terms →</a>
<br>
<a href="/privacy-policy" style="color: #667eea; text-decoration: none; font-size: var(--font-sm);">View Full Privacy Policy →</a>
</div>
</div>
</div>
</div>
<!-- Toast Notification -->
<div class="toast" id="toast"></div>
<script>
// State - will be initialized based on login type
let currentMode = 'passenger';
// Initialize - load profile from server first, then localStorage as fallback
document.addEventListener('DOMContentLoaded', async function() {
// First try to load from localStorage as fallback
let userName = localStorage.getItem('pdrides_name') || 'User';
let userPhone = localStorage.getItem('pdrides_phone') || '';
const userPhoto = localStorage.getItem('pdrides_photo');
// Get auth credentials
const authToken = localStorage.getItem('pdrides_token');
// Get user's driver status from registration - this determines the initial mode
const isDriver = localStorage.getItem('pdrides_isDriver') === 'true';
const userRoles = JSON.parse(localStorage.getItem('pdrides_roles') || '{"passenger":true,"driver":false}');
// Determine initial mode based on login type:
// - If user registered as driver only, start in driver mode
// - If user registered as passenger only, start in passenger mode
// - If user has both roles, use saved mode or default to passenger
let initialMode = 'passenger';
if (authToken && userPhone) {
if (isDriver && !userRoles.passenger) {
// User registered as driver only - start in driver mode
initialMode = 'driver';
} else if (!isDriver && userRoles.passenger && !userRoles.driver) {
// User registered as passenger only - start in passenger mode
initialMode = 'passenger';
} else if (userRoles.driver && userRoles.passenger) {
// User has both roles - use saved mode or default to passenger
initialMode = localStorage.getItem('pdrides_mode') || 'passenger';
}
// Save the initial mode
localStorage.setItem('pdrides_mode', initialMode);
}
// Try to fetch from server if logged in
if (authToken && userPhone) {
try {
const response = await fetch(`/api/user/profile?phoneNumber=${userPhone}&token=${authToken}`);
const data = await response.json();
if (data.success && data.profile) {
// Update with server data
userName = data.profile.name || userName;
userPhone = data.profile.phoneNumber || userPhone;
// Save to localStorage for consistency
localStorage.setItem('pdrides_name', userName);
localStorage.setItem('pdrides_phone', userPhone);
// Pre-fill edit profile form with server data
document.getElementById('profileNameInput').value = data.profile.name || '';
document.getElementById('profileEmailInput').value = data.profile.email || '';
document.getElementById('emergencyContactName').value = data.profile.emergencyContact?.name || '';
document.getElementById('emergencyContactPhone').value = data.profile.emergencyContact?.phone || '';
}
} catch (error) {
console.error('Error fetching profile:', error);
}
}
// Update profile card
updateProfileAvatar(userPhoto, userName);
document.getElementById('profileName').textContent = userName;
document.getElementById('profilePhone').textContent = userPhone;
// Update role toggle visibility based on user roles
updateRoleToggleVisibility(userRoles, isDriver, authToken && userPhone);
// Set mode based on login type - this will initialize the correct mode
setUserMode(initialMode, false);
});
// Update role toggle visibility based on user registration
function updateRoleToggleVisibility(userRoles, isDriver, isLoggedIn) {
const passengerBtn = document.getElementById('passengerModeBtn');
const driverBtn = document.getElementById('driverModeBtn');
if (!isLoggedIn) {
// Not logged in - show both buttons
passengerBtn.style.display = 'block';
driverBtn.style.display = 'block';
passengerBtn.disabled = false;
driverBtn.disabled = false;
return;
}
// If user has both roles, show both buttons
if (userRoles && userRoles.passenger && userRoles.driver) {
passengerBtn.style.display = 'block';
driverBtn.style.display = 'block';
passengerBtn.disabled = false;
driverBtn.disabled = false;
}
// Only driver registered - show only driver button
else if (userRoles && userRoles.driver && !userRoles.passenger) {
passengerBtn.style.display = 'none';
driverBtn.style.display = 'block';
}
// Only passenger registered (default) - show only passenger button
else {
passengerBtn.style.display = 'block';
driverBtn.style.display = 'none';
}
}
// Update profile avatar with photo or initials
function updateProfileAvatar(photoData, name) {
const avatar = document.getElementById('profileAvatar');
if (photoData) {
avatar.innerHTML = '<img src="' + photoData + '" alt="Profile Photo">';
avatar.classList.add('has-image');
} else {
avatar.textContent = name.charAt(0).toUpperCase();
avatar.classList.remove('has-image');
avatar.style.background = 'linear-gradient(135deg, #25D366 0%, #128C7E 100%)';
}
}
// Handle profile photo upload
function handleProfilePhotoUpload(event) {
const file = event.target.files[0];
if (!file) {
return;
}
// Validate file type
if (!file.type.startsWith('image/')) {
showToast('Please select an image file', 'error');
return;
}
// Validate file size (max 5MB)
if (file.size > 5 * 1024 * 1024) {
showToast('Image must be less than 5MB', 'error');
return;
}
// Read and display the image
const reader = new FileReader();
reader.onload = function(e) {
const photoData = e.target.result;
// Save to localStorage
localStorage.setItem('pdrides_photo', photoData);
// Update avatar display
const userName = localStorage.getItem('pdrides_name') || 'User';
updateProfileAvatar(photoData, userName);
// Update profile photo across all views (stored in localStorage for other pages to use)
showToast('Profile photo updated!', 'success');
};
reader.onerror = function() {
showToast('Error reading file', 'error');
};
reader.readAsDataURL(file);
}
// Set user mode
function setUserMode(mode, showToastMessage = true) {
currentMode = mode;
localStorage.setItem('pdrides_mode', mode);
// Update buttons
document.getElementById('passengerModeBtn').classList.toggle('active', mode === 'passenger');
document.getElementById('driverModeBtn').classList.toggle('active', mode === 'driver');
// Update body class
document.body.classList.toggle('driver-mode', mode === 'driver');
// Update background wrapper class
document.querySelector('.background-wrapper').classList.toggle('driver-mode', mode === 'driver');
// Update driver settings visibility
const driverCard = document.getElementById('driverSettingsCard');
driverCard.style.display = mode === 'driver' ? 'block' : 'none';
// Update profile badge
const badge = document.getElementById('profileBadge');
badge.textContent = mode === 'driver' ? 'Driver' : 'Passenger';
badge.className = 'profile-badge ' + mode;
// Show toast only if explicitly requested (not during initial load)
if (showToastMessage) {
showToast(`Switched to ${mode} mode`, 'success');
}
}
// Modal functions
function showEditProfileModal() {
document.getElementById('editProfileModal').classList.add('active');
}
function showChangePasswordModal() {
document.getElementById('changePasswordModal').classList.add('active');
}
function showNotificationSettings() {
document.getElementById('notificationSettingsModal').classList.add('active');
}
function showPrivacySettings() {
document.getElementById('privacySettingsModal').classList.add('active');
}
function showVehicleInfoModal() {
document.getElementById('vehicleInfoModal').classList.add('active');
}
function showDriverPreferencesModal() {
document.getElementById('driverPreferencesModal').classList.add('active');
}
function showDeleteAccountModal() {
document.getElementById('deleteAccountModal').classList.add('active');
}
function showContact() {
document.getElementById('contactModal').classList.add('active');
}
function closeModal(modalId) {
document.getElementById(modalId).classList.remove('active');
}
// Close modal on overlay click
document.querySelectorAll('.modal-overlay').forEach(function(overlay) {
overlay.addEventListener('click', function(e) {
if (e.target === overlay) {
overlay.classList.remove('active');
}
});
});
// Save profile function
function saveProfile() {
const btn = document.getElementById('saveProfileBtn');
const name = document.getElementById('profileNameInput').value.trim();
const email = document.getElementById('profileEmailInput').value.trim();
const emergencyName = document.getElementById('emergencyContactName').value.trim();
const emergencyPhone = document.getElementById('emergencyContactPhone').value.trim();
if (!name) {
showToast('Please enter your name', 'error');
return;
}
// Get auth credentials from localStorage
const authToken = localStorage.getItem('pdrides_token');
const userPhone = localStorage.getItem('pdrides_phone');
if (!authToken || !userPhone) {
showToast('Please login first', 'error');
// Redirect to login if no token
setTimeout(() => {
window.location.href = '/login';
}, 1500);
return;
}
btn.disabled = true;
btn.innerHTML = '<span class="loading"></span>Saving...';
// Prepare request data
const requestData = {
name: name,
email: email,
emergencyContact: {
name: emergencyName,
phone: emergencyPhone
}
};
// Build URL with query parameters for authentication (as fallback)
const queryParams = `?phoneNumber=${encodeURIComponent(userPhone)}&token=${encodeURIComponent(authToken)}`;
// Call API to update profile - include auth in both headers and URL params
fetch('/api/user/profile' + queryParams, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'phoneNumber': userPhone,
'token': authToken
},
body: JSON.stringify(requestData)
})
.then(response => {
// Check if response is JSON
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/json')) {
return response.json().then(data => ({ status: response.status, data }));
} else {
return { status: response.status, data: { success: false, error: 'Server error' } };
}
})
.then(result => {
btn.disabled = false;
btn.innerHTML = 'Save Changes';
if (result.data.success) {
// Update localStorage with new name for display across the app
localStorage.setItem('pdrides_name', name);
// Update profile card display
document.getElementById('profileName').textContent = name;
updateProfileAvatar(localStorage.getItem('pdrides_photo'), name);
// Dispatch custom event for other pages to update name in real-time
window.dispatchEvent(new CustomEvent('profileNameUpdated', { detail: { name: name } }));
closeModal('editProfileModal');
showToast('Profile updated successfully!', 'success');
} else {
// Handle authentication errors specifically
if (result.status === 401 || result.data.error?.includes('Authentication') || result.data.error?.includes('login')) {
showToast('Session expired. Please login again.', 'error');
// Clear token and redirect to login
setTimeout(() => {
localStorage.removeItem('pdrides_token');
window.location.href = '/login';
}, 2000);
} else {
showToast(result.data.error || 'Failed to update profile', 'error');
}
}
})
.catch(error => {
console.error('Error saving profile:', error);
btn.disabled = false;
btn.innerHTML = 'Save Changes';
showToast('Failed to update profile. Please check your connection.', 'error');
});
}
function changePassword() {
const current = document.getElementById('currentPassword').value;
const newPass = document.getElementById('newPassword').value;
const confirm = document.getElementById('confirmNewPassword').value;
if (!current || !newPass || !confirm) {
showToast('Please fill in all fields', 'error');
return;
}
if (newPass !== confirm) {
showToast('Passwords do not match', 'error');
return;
}
if (newPass.length < 6) {
showToast('Password must be at least 6 characters', 'error');
return;
}
// Simulate change
showToast('Password changed successfully!', 'success');
closeModal('changePasswordModal');
// Clear fields
document.getElementById('currentPassword').value = '';
document.getElementById('newPassword').value = '';
document.getElementById('confirmNewPassword').value = '';
}
function saveNotificationSettings() {
showToast('Notification settings saved!', 'success');
closeModal('notificationSettingsModal');
}
function savePrivacySettings() {
showToast('Privacy settings saved!', 'success');
closeModal('privacySettingsModal');
}
function saveVehicleInfo() {
showToast('Vehicle information saved!', 'success');
closeModal('vehicleInfoModal');
}
function saveDriverPreferences() {
showToast('Driving preferences saved!', 'success');
closeModal('driverPreferencesModal');
}
function downloadData() {
showToast('Preparing your data for download...', 'success');
}
function deleteAccount() {
const confirmation = document.getElementById('deleteConfirmation').value;
if (confirmation !== 'DELETE') {
showToast('Please type DELETE to confirm', 'error');
return;
}
// Get auth credentials from localStorage
const authToken = localStorage.getItem('pdrides_token');
const userPhone = localStorage.getItem('pdrides_phone');
if (!authToken || !userPhone) {
showToast('Please login first', 'error');
// Redirect to login if no token
setTimeout(() => {
window.location.href = '/login';
}, 1500);
return;
}
// Show loading state on button
const deleteBtn = event.target;
const originalText = deleteBtn.textContent;
deleteBtn.disabled = true;
deleteBtn.innerHTML = '<span class="loading"></span>Deleting...';
// Build URL with query parameters for authentication
const queryParams = `?phoneNumber=${encodeURIComponent(userPhone)}&token=${encodeURIComponent(authToken)}`;
// Call API to delete account
fetch('/api/user/account' + queryParams, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'phoneNumber': userPhone,
'token': authToken
}
})
.then(response => {
// Check if response is JSON
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/json')) {
return response.json().then(data => ({ status: response.status, data }));
} else {
return { status: response.status, data: { success: false, error: 'Server error' } };
}
})
.then(result => {
// Reset button state
deleteBtn.disabled = false;
deleteBtn.textContent = originalText;
if (result.data.success) {
// Close modal
closeModal('deleteAccountModal');
// Show success message
showToast('Account deleted successfully!', 'success');
// Clear all localStorage data
localStorage.clear();
// Redirect to login page after a short delay