11/** @jsxImportSource @emotion /react */
22import React , { useEffect , useState , useRef } from 'react' ;
33
4+ import { Button } from '@orfium/ictinus' ;
45import { IconButton , Filter } from '@orfium/ictinus' ;
56import { FilterOption } from '@orfium/ictinus/dist/components/Filter/types' ;
67import { ReactComponent as SortIcon } from 'assets/PatientDirectory/sortIcon.svg' ;
@@ -24,9 +25,56 @@ const PatientDirectory: React.FC<{ searchTerm?: string }> = ({ searchTerm }) =>
2425 ( localStorage . getItem ( 'sortingOption' ) as SortingOptionsType ) || '-created_at'
2526 ) ;
2627
28+ const [ page , setPage ] = useState ( 1 ) ;
29+
30+ const limit = 10 ;
31+
32+ const offset = ( page - 1 ) * limit ;
33+
34+ const PaginationControls : React . FC < {
35+ page : number ;
36+ total : number ;
37+ limit : number ;
38+ onPageChange : ( newPage : number ) => void ;
39+ } > = ( { page, total, limit, onPageChange } ) => {
40+ const totalPages = Math . ceil ( total / limit ) ;
41+ const start = ( page - 1 ) * limit + 1 ;
42+ const end = Math . min ( page * limit , total ) ;
43+
44+ return (
45+ < div
46+ css = { {
47+ display : 'flex' ,
48+ justifyContent : 'center' ,
49+ alignItems : 'center' ,
50+ gap : '12px' ,
51+ margin : '16px 0' ,
52+ } }
53+ >
54+ < Button
55+ size = "sm"
56+ disabled = { page === 1 }
57+ onClick = { ( ) => onPageChange ( page - 1 ) }
58+ >
59+ Previous
60+ </ Button >
61+ < span css = { { fontSize : 14 } } >
62+ Patients { start } -{ end } out of { total }
63+ </ span >
64+ < Button
65+ size = "sm"
66+ disabled = { page === totalPages }
67+ onClick = { ( ) => onPageChange ( page + 1 ) }
68+ >
69+ Next
70+ </ Button >
71+ </ div >
72+ ) ;
73+ } ;
74+
2775 const { data : patients } = useGetPatients ( {
28- offset : 0 ,
29- limit : 100 ,
76+ offset,
77+ limit,
3078 search_term : searchTerm ,
3179 hospital_id : hospitalId ,
3280 ordering : sortingOption ,
@@ -85,6 +133,15 @@ const PatientDirectory: React.FC<{ searchTerm?: string }> = ({ searchTerm }) =>
85133 < SortIcon onClick = { ( ) => setShowSortingOptions ( ! showSortingOptions ) } />
86134 </ OptionsWrapper >
87135
136+ { patients && patients . count > limit && (
137+ < PaginationControls
138+ page = { page }
139+ total = { patients . count }
140+ limit = { limit }
141+ onPageChange = { ( newPage ) => setPage ( newPage ) }
142+ />
143+ ) }
144+
88145 { patients && (
89146 < PatientsList >
90147 { patients . results . map ( ( patient ) => (
0 commit comments