11'use client' ;
22
3+ import { useState } from 'react' ;
34import { useStaffAuth } from '../../../../staff/auth/staff.auth.provider' ;
45import { useDoctorQueue } from '../../../../features/appointments/hooks/useDoctorQueue' ;
6+ import {
7+ useStartAppointment ,
8+ useCompleteAppointment ,
9+ useCheckInAppointment ,
10+ } from '../../../../features/appointments/hooks/useStaffActions' ;
11+ import { useEmergency } from '../../../../features/appointments/hooks/useEmergency' ;
512
613export default function QueuePage ( ) {
714 const { auth } = useStaffAuth ( ) ;
8-
915 const doctorId = auth . staff ?. id ;
1016
11- // Wait until auth restoration finishes
12- if ( auth . isRestoring ) {
13- return < p > Loading authentication...</ p > ;
14- }
17+ const [ showEmergency , setShowEmergency ] = useState ( false ) ;
18+ const [ patientId , setPatientId ] = useState ( '' ) ;
19+
20+ if ( auth . isRestoring ) return < p > Loading authentication...</ p > ;
21+ if ( ! doctorId ) return < p > Doctor information not available.</ p > ;
1522
16- if ( ! doctorId ) {
17- return < p > Doctor information not available.</ p > ;
18- }
23+ const { data, isLoading } = useDoctorQueue ( doctorId ) ;
1924
20- const { data, isLoading, isError } =
21- useDoctorQueue ( doctorId ) ;
25+ const startMutation = useStartAppointment ( ) ;
26+ const completeMutation = useCompleteAppointment ( ) ;
27+ const checkInMutation = useCheckInAppointment ( ) ;
28+ const emergencyMutation = useEmergency ( doctorId ) ;
2229
2330 if ( isLoading ) return < p > Loading queue...</ p > ;
24- if ( isError ) return < p > Failed to load queue.</ p > ;
2531 if ( ! data ) return < p > No queue found.</ p > ;
2632
2733 const { queue, doctor_status } = data ;
34+ const someoneInProgress = queue . some ( ( q : any ) => q . status === 'IN_PROGRESS' ) ;
2835
2936 return (
3037 < div className = "space-y-8" >
3138
32- < h1 className = "text-2xl font-bold" >
33- Today's Queue
34- </ h1 >
39+ { /* 🔴 Emergency Button */ }
40+ < div className = "flex justify-between items-center" >
41+ < h1 className = "text-2xl font-bold" > Today's Queue</ h1 >
42+
43+ < button
44+ onClick = { ( ) => setShowEmergency ( true ) }
45+ className = "bg-red-600 text-white px-4 py-2 rounded-lg shadow hover:bg-red-700 transition"
46+ >
47+ + Emergency Case
48+ </ button >
49+ </ div >
3550
3651 { /* Doctor Status Panel */ }
3752 < div className = "bg-white p-6 rounded shadow space-y-2" >
38- < p >
39- < strong > Total Appointments:</ strong > { ' ' }
40- { doctor_status . total_appointments }
41- </ p >
42- < p >
43- < strong > Checked In:</ strong > { ' ' }
44- { doctor_status . checked_in_count }
45- </ p >
46- < p >
47- < strong > Doctor Delay:</ strong > { ' ' }
48- { doctor_status . doctor_delay_minutes } min
49- </ p >
50- < p >
51- < strong > Remaining Queue:</ strong > { ' ' }
52- { doctor_status . remaining_queue_minutes } min
53- </ p >
53+ < p > < strong > Total:</ strong > { doctor_status . total_appointments } </ p >
54+ < p > < strong > Checked In:</ strong > { doctor_status . checked_in_count } </ p >
55+ < p > < strong > Delay:</ strong > { doctor_status . doctor_delay_minutes } min</ p >
56+ < p > < strong > Remaining:</ strong > { doctor_status . remaining_queue_minutes } min</ p >
5457 </ div >
5558
5659 { /* Queue List */ }
@@ -59,32 +62,97 @@ export default function QueuePage() {
5962 < div
6063 key = { item . id }
6164 className = { `p-4 rounded border shadow-sm ${
62- item . is_current
63- ? 'bg-green-100 border-green-400'
64- : item . priority === 'HIGH'
65+ item . priority === 'HIGH'
6566 ? 'bg-red-50 border-red-300'
67+ : item . is_current
68+ ? 'bg-green-100 border-green-400'
6669 : 'bg-white'
6770 } `}
6871 >
69- < div className = "flex justify-between items-center" >
70- < div >
71- < p className = "font-semibold" >
72- Patient ID: { item . patient_id }
73- </ p >
74- < p > Status: { item . status } </ p >
75- < p > Position: { item . position } </ p >
76- < p > Delay: { item . delay_minutes } min</ p >
77- </ div >
78-
79- { item . priority === 'HIGH' && (
80- < span className = "px-3 py-1 text-sm bg-red-500 text-white rounded-full" >
81- HIGH
82- </ span >
72+ < p className = "font-semibold" >
73+ Patient ID: { item . patient_id }
74+ </ p >
75+ < p > Status: { item . status } </ p >
76+ < p > Position: { item . position } </ p >
77+
78+ < div className = "flex gap-2 mt-3" >
79+
80+ { item . status === 'SCHEDULED' && (
81+ < button
82+ onClick = { ( ) => checkInMutation . mutate ( item . id ) }
83+ className = "px-3 py-1 bg-yellow-500 text-white rounded text-sm"
84+ >
85+ Check In
86+ </ button >
87+ ) }
88+
89+ { item . status === 'CHECKED_IN' && ! someoneInProgress && (
90+ < button
91+ onClick = { ( ) => startMutation . mutate ( item . id ) }
92+ className = "px-3 py-1 bg-blue-600 text-white rounded text-sm"
93+ >
94+ Start
95+ </ button >
8396 ) }
97+
98+ { item . status === 'IN_PROGRESS' && (
99+ < button
100+ onClick = { ( ) => completeMutation . mutate ( item . id ) }
101+ className = "px-3 py-1 bg-green-600 text-white rounded text-sm"
102+ >
103+ Complete
104+ </ button >
105+ ) }
106+
84107 </ div >
85108 </ div >
86109 ) ) }
87110 </ div >
111+
112+ { /* 🔴 Emergency Modal */ }
113+ { showEmergency && (
114+ < div className = "fixed inset-0 bg-black/40 flex items-center justify-center" >
115+
116+ < div className = "bg-white p-6 rounded-xl w-96 space-y-4 shadow-xl" >
117+
118+ < h2 className = "text-xl font-semibold text-red-600" >
119+ Create Emergency Case
120+ </ h2 >
121+
122+ < input
123+ type = "text"
124+ placeholder = "Enter Patient ID"
125+ value = { patientId }
126+ onChange = { ( e ) => setPatientId ( e . target . value ) }
127+ className = "w-full border rounded px-3 py-2"
128+ />
129+
130+ < div className = "flex justify-end gap-3" >
131+
132+ < button
133+ onClick = { ( ) => setShowEmergency ( false ) }
134+ className = "px-4 py-2 rounded border"
135+ >
136+ Cancel
137+ </ button >
138+
139+ < button
140+ onClick = { ( ) => {
141+ emergencyMutation . mutate ( patientId ) ;
142+ setShowEmergency ( false ) ;
143+ setPatientId ( '' ) ;
144+ } }
145+ className = "px-4 py-2 bg-red-600 text-white rounded"
146+ >
147+ Confirm Emergency
148+ </ button >
149+
150+ </ div >
151+
152+ </ div >
153+ </ div >
154+ ) }
155+
88156 </ div >
89157 ) ;
90158}
0 commit comments