1
+ function logout ( ) {
2
+ const logoutButton = document . querySelector ( 'button[onclick="logout()"]' ) ;
3
+
4
+ if ( logoutButton ) {
5
+ logoutButton . disabled = true ;
6
+ logoutButton . innerText = "Logging out..." ;
7
+ }
8
+
9
+ localStorage . removeItem ( "access" ) ;
10
+
11
+ setTimeout ( ( ) => {
12
+ window . location . href = "/login/" ;
13
+ } , 500 ) ;
14
+ }
15
+
16
+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
17
+
18
+ const scheduleButtons = document . querySelectorAll ( '.action-card .btn' ) ;
19
+ if ( scheduleButtons [ 0 ] ) {
20
+ scheduleButtons [ 0 ] . addEventListener ( 'click' , function ( ) {
21
+ alert ( 'Schedule appointment feature coming soon!' ) ;
22
+ } ) ;
23
+ }
24
+
25
+ if ( scheduleButtons [ 1 ] ) {
26
+ scheduleButtons [ 1 ] . addEventListener ( 'click' , function ( ) {
27
+ alert ( 'View records feature coming soon!' ) ;
28
+ } ) ;
29
+ }
30
+
31
+ if ( scheduleButtons [ 2 ] ) {
32
+ scheduleButtons [ 2 ] . addEventListener ( 'click' , function ( ) {
33
+ alert ( 'Manage prescriptions feature coming soon!' ) ;
34
+ } ) ;
35
+ }
36
+
37
+ const statCards = document . querySelectorAll ( '.stat-card' ) ;
38
+ statCards . forEach ( card => {
39
+ card . addEventListener ( 'click' , function ( ) {
40
+
41
+ const statLabel = this . querySelector ( '.stat-label' ) . textContent ;
42
+ alert ( `${ statLabel } details coming soon!` ) ;
43
+ } ) ;
44
+
45
+ card . style . cursor = 'pointer' ;
46
+ } ) ;
47
+
48
+ const actionCards = document . querySelectorAll ( '.action-card' ) ;
49
+ actionCards . forEach ( card => {
50
+ card . addEventListener ( 'mouseenter' , function ( ) {
51
+ this . style . transform = 'translateY(-5px)' ;
52
+ } ) ;
53
+
54
+ card . addEventListener ( 'mouseleave' , function ( ) {
55
+ this . style . transform = 'translateY(0)' ;
56
+ } ) ;
57
+ } ) ;
58
+ } ) ;
59
+
60
+ async function validateToken ( ) {
61
+ const token = localStorage . getItem ( "access" ) ;
62
+ if ( ! token ) return false ;
63
+
64
+ try {
65
+ const res = await fetch ( "/api/validate-token/" , {
66
+ method : "GET" ,
67
+ headers : {
68
+ "Authorization" : `Bearer ${ token } ` ,
69
+ "Content-Type" : "application/json"
70
+ }
71
+ } ) ;
72
+
73
+ if ( ! res . ok ) {
74
+ localStorage . removeItem ( "access" ) ;
75
+ window . location . href = "/login/" ;
76
+ return false ;
77
+ }
78
+
79
+ return true ;
80
+ } catch ( error ) {
81
+ console . log ( "Token validation failed:" , error ) ;
82
+ return true ;
83
+ }
84
+ }
0 commit comments