@@ -12,42 +12,99 @@ import { useEmergency } from '../../../../features/appointments/hooks/useEmergen
1212import { useRequestAdmission } from '../../../../features/admissions/hooks/useRequestAdmission' ;
1313import { Activity , Clock , Users , Timer , CheckCircle , AlertCircle } from 'lucide-react' ;
1414import { PrescribeModal } from '../../../../features/pharmacy/components/PrescribeModal' ;
15+ import { useDepartments , useDoctorsByDepartment } from '../../../../features/staff/hooks/useStaffData' ;
1516
1617export default function QueuePage ( ) {
1718 const { auth } = useStaffAuth ( ) ;
18- const doctorId = auth . staff ?. id ;
19+ const isDoctor = auth . staff ?. role === 'DOCTOR' ;
1920
21+ const [ selectedDeptId , setSelectedDeptId ] = useState ( '' ) ;
22+ const [ selectedDoctorId , setSelectedDoctorId ] = useState ( isDoctor ? auth . staff ?. id : '' ) ;
2023 const [ showEmergency , setShowEmergency ] = useState ( false ) ;
2124 const [ patientId , setPatientId ] = useState ( '' ) ;
2225 const [ prescribePatient , setPrescribePatient ] = useState < { id : string , name : string } | null > ( null ) ;
2326
27+ const { data : departments } = useDepartments ( ) ;
28+ const { data : doctorsInDept , isLoading : isLoadingDoctors } = useDoctorsByDepartment ( selectedDeptId ) ;
29+
30+ const statuses = isDoctor ? [ 'CHECKED_IN' , 'IN_PROGRESS' ] : [ 'SCHEDULED' , 'CHECKED_IN' , 'IN_PROGRESS' ] ;
31+ const { data, isLoading } = useDoctorQueue ( selectedDoctorId , statuses ) ;
32+
33+ const startMutation = useStartAppointment ( ) ;
34+ const completeMutation = useCompleteAppointment ( ) ;
35+ const checkInMutation = useCheckInAppointment ( ) ;
36+ const emergencyMutation = useEmergency ( selectedDoctorId || '' ) ;
37+ const admitMutation = useRequestAdmission ( ) ;
38+
2439 if ( auth . isRestoring ) return (
2540 < div className = "flex justify-center p-8" >
2641 < div className = "h-8 w-8 animate-spin rounded-full border-2 border-gray-300 border-t-blue-600" />
2742 </ div >
2843 ) ;
29- if ( ! doctorId ) return (
30- < div className = "bg-white rounded-2xl border shadow-sm p-6 text-slate-500 text-center" >
31- Doctor information not available.
32- </ div >
33- ) ;
3444
35- const { data, isLoading } = useDoctorQueue ( doctorId ) ;
45+ if ( ! isDoctor && ! selectedDoctorId ) {
46+ return (
47+ < div className = "space-y-6" >
48+ < div className = "bg-white p-8 rounded-2xl shadow-sm border text-center space-y-6 max-w-2xl mx-auto" >
49+ < div className = "space-y-2" >
50+ < Activity size = { 48 } className = "mx-auto text-indigo-500 opacity-50" />
51+ < h2 className = "text-2xl font-bold text-slate-800" > Staff Check-in Panel</ h2 >
52+ < p className = "text-slate-500" > Select a department and doctor to manage their queue.</ p >
53+ </ div >
3654
37- const startMutation = useStartAppointment ( ) ;
38- const completeMutation = useCompleteAppointment ( ) ;
39- const checkInMutation = useCheckInAppointment ( ) ;
40- const emergencyMutation = useEmergency ( doctorId ) ;
41- const admitMutation = useRequestAdmission ( ) ;
55+ < div className = "grid grid-cols-1 sm:grid-cols-2 gap-4 text-left" >
56+ < div className = "space-y-2" >
57+ < label className = "text-sm font-semibold text-slate-700" > Department</ label >
58+ < select
59+ value = { selectedDeptId }
60+ onChange = { ( e ) => setSelectedDeptId ( e . target . value ) }
61+ className = "w-full border border-slate-300 rounded-xl px-4 py-3 focus:ring-2 focus:ring-indigo-500 outline-none bg-white transition"
62+ >
63+ < option value = "" > Select Department...</ option >
64+ { departments ?. map ( ( dept : any ) => (
65+ < option key = { dept . id } value = { dept . id } > { dept . name } </ option >
66+ ) ) }
67+ </ select >
68+ </ div >
69+
70+ < div className = "space-y-2" >
71+ < label className = "text-sm font-semibold text-slate-700" > Doctor</ label >
72+ < select
73+ disabled = { ! selectedDeptId || isLoadingDoctors }
74+ onChange = { ( e ) => setSelectedDoctorId ( e . target . value ) }
75+ className = "w-full border border-slate-300 rounded-xl px-4 py-3 focus:ring-2 focus:ring-indigo-500 outline-none bg-white disabled:bg-slate-50 disabled:text-slate-400 transition"
76+ value = "" // Keep it as placeholder since we set selectedDoctorId on change
77+ >
78+ < option value = "" >
79+ { isLoadingDoctors ? 'Loading doctors...' : selectedDeptId ? 'Select Doctor...' : 'Select Department first...' }
80+ </ option >
81+ { doctorsInDept ?. map ( ( doc : any ) => (
82+ < option key = { doc . id } value = { doc . id } > { doc . name } </ option >
83+ ) ) }
84+ </ select >
85+ </ div >
86+ </ div >
87+ </ div >
88+ </ div >
89+ ) ;
90+ }
91+
92+ const doctorId = selectedDoctorId ;
4293
4394 if ( isLoading ) return (
4495 < div className = "flex justify-center p-8" >
4596 < div className = "h-8 w-8 animate-spin rounded-full border-2 border-gray-300 border-t-blue-600" />
4697 </ div >
4798 ) ;
99+
48100 if ( ! data ) return (
49101 < div className = "bg-white rounded-2xl border shadow-sm p-6 text-slate-500 text-center" >
50- No queue found.
102+ No queue found for this doctor.
103+ { ! isDoctor && (
104+ < button onClick = { ( ) => setSelectedDoctorId ( '' ) } className = "block mx-auto mt-4 text-indigo-600 font-medium" >
105+ Change Doctor
106+ </ button >
107+ ) }
51108 </ div >
52109 ) ;
53110
@@ -59,12 +116,22 @@ export default function QueuePage() {
59116
60117 { /* 🔴 Header */ }
61118 < div className = "flex justify-between items-center bg-white p-6 rounded-2xl shadow-sm border" >
62- < h1 className = "text-2xl font-bold text-slate-800 flex items-center gap-3" >
63- < div className = "p-2.5 rounded-xl bg-indigo-100 text-indigo-600" >
64- < Activity size = { 24 } />
65- </ div >
66- Today's Queue
67- </ h1 >
119+ < div className = "flex items-center gap-4" >
120+ < h1 className = "text-2xl font-bold text-slate-800 flex items-center gap-3" >
121+ < div className = "p-2.5 rounded-xl bg-indigo-100 text-indigo-600" >
122+ < Activity size = { 24 } />
123+ </ div >
124+ { isDoctor ? "Today's Queue" : "Staff Check-in" }
125+ </ h1 >
126+ { ! isDoctor && (
127+ < button
128+ onClick = { ( ) => setSelectedDoctorId ( '' ) }
129+ className = "px-3 py-1 text-xs bg-slate-100 hover:bg-slate-200 text-slate-600 rounded-lg transition"
130+ >
131+ Switch Doctor
132+ </ button >
133+ ) }
134+ </ div >
68135
69136 < button
70137 onClick = { ( ) => setShowEmergency ( true ) }
@@ -116,7 +183,7 @@ export default function QueuePage() {
116183 < div className = "grid grid-cols-1 gap-4" >
117184 { queue . length === 0 ? (
118185 < div className = "bg-white rounded-2xl border shadow-sm p-6 text-slate-500 text-center" >
119- The queue is currently empty.
186+ { isDoctor ? "No patients ready for consultation." : "No upcoming appointments for this doctor." }
120187 </ div >
121188 ) : queue . map ( ( item : any ) => (
122189 < div
@@ -154,8 +221,8 @@ export default function QueuePage() {
154221
155222 < div className = "flex gap-3 flex-wrap" >
156223
157- { /* Check In */ }
158- { item . status === 'SCHEDULED' && (
224+ { /* Check In - STAFF ONLY */ }
225+ { ! isDoctor && item . status === 'SCHEDULED' && (
159226 < button
160227 onClick = { ( ) => checkInMutation . mutate ( item . id ) }
161228 className = "px-5 py-2.5 bg-yellow-500 hover:bg-yellow-600 text-white rounded-xl text-sm font-medium transition shadow-sm"
@@ -164,8 +231,8 @@ export default function QueuePage() {
164231 </ button >
165232 ) }
166233
167- { /* Start Consultation */ }
168- { item . status === 'CHECKED_IN' && ! someoneInProgress && (
234+ { /* Start Consultation - DOCTOR ONLY */ }
235+ { isDoctor && item . status === 'CHECKED_IN' && ! someoneInProgress && (
169236 < button
170237 onClick = { ( ) => startMutation . mutate ( item . id ) }
171238 className = "px-5 py-2.5 bg-blue-600 hover:bg-blue-700 text-white rounded-xl text-sm font-medium transition shadow-sm"
@@ -174,8 +241,8 @@ export default function QueuePage() {
174241 </ button >
175242 ) }
176243
177- { /* Complete Consultation */ }
178- { item . status === 'IN_PROGRESS' && (
244+ { /* Complete Consultation - DOCTOR ONLY */ }
245+ { isDoctor && item . status === 'IN_PROGRESS' && (
179246 < >
180247 < button
181248 onClick = { ( ) => setPrescribePatient ( { id : item . patient_id , name : item . patient_name } ) }
@@ -202,7 +269,7 @@ export default function QueuePage() {
202269 onClick = { ( ) =>
203270 admitMutation . mutate ( {
204271 patientId : item . patient_id ,
205- doctorId : doctorId ,
272+ doctorId : doctorId as string ,
206273 departmentId : auth . staff ?. department_id as string
207274 } )
208275 }
0 commit comments