@@ -117,6 +117,8 @@ const SupplierListContent = ({
117117} ) => {
118118 const [ showCreateForm , setShowCreateForm ] = useState < boolean > ( false ) ;
119119 const [ isImportPending , setIsImportPending ] = useState < boolean > ( false ) ;
120+ const [ currentPage , setCurrentPage ] = useState < number > ( 0 ) ;
121+ const [ pageSize ] = useState < number > ( 10 ) ;
120122 const fileInputRef = useRef < HTMLInputElement > ( null ) ;
121123 const [ createForm , setCreateForm ] = useState < CreateSupplierInput > ( {
122124 name : '' ,
@@ -139,6 +141,8 @@ const SupplierListContent = ({
139141
140142 const suppliers = data . suppliers ?. items || [ ] ;
141143 const totalItems = data . suppliers ?. totalItems || 0 ;
144+ const numPages = data . suppliers ?. numPages || 1 ;
145+ const currentPageFromData = data . suppliers ?. page || 0 ;
142146
143147 const handleCreateSupplier = ( ) => {
144148 if ( createForm . name . trim ( ) && createForm . contactEmail . trim ( ) ) {
@@ -163,9 +167,10 @@ const SupplierListContent = ({
163167 website : ''
164168 } ) ;
165169 setShowCreateForm ( false ) ;
166- // Force network fetch to bypass cache
170+ // Force network fetch to bypass cache and reset to first page
171+ setCurrentPage ( 0 ) ;
167172 loadQuery (
168- { page : 0 , pageSize : 10 } ,
173+ { page : 0 , pageSize } ,
169174 { fetchPolicy : 'network-only' }
170175 ) ;
171176 } ,
@@ -183,8 +188,17 @@ const SupplierListContent = ({
183188 onCompleted : ( response ) => {
184189 if ( response . deleteSupplier ) {
185190 // Force network fetch to bypass cache and show updated list
191+ // Check if current page would be empty after deletion, go to previous page
192+ const remainingItems = totalItems - 1 ;
193+ const maxPage = Math . max ( 0 , Math . ceil ( remainingItems / pageSize ) - 1 ) ;
194+ const targetPage = Math . min ( currentPage , maxPage ) ;
195+
196+ if ( targetPage !== currentPage ) {
197+ setCurrentPage ( targetPage ) ;
198+ }
199+
186200 loadQuery (
187- { page : 0 , pageSize : 10 } ,
201+ { page : targetPage , pageSize } ,
188202 { fetchPolicy : 'network-only' }
189203 ) ;
190204 }
@@ -336,9 +350,10 @@ const SupplierListContent = ({
336350 if ( fileInputRef . current ) {
337351 fileInputRef . current . value = '' ;
338352 }
339- // Refresh the list
353+ // Refresh the list and reset to first page
354+ setCurrentPage ( 0 ) ;
340355 loadQuery (
341- { page : 0 , pageSize : 10 } ,
356+ { page : 0 , pageSize } ,
342357 { fetchPolicy : 'network-only' }
343358 ) ;
344359 } ,
@@ -355,6 +370,28 @@ const SupplierListContent = ({
355370 }
356371 } ;
357372
373+ const handlePreviousPage = ( ) => {
374+ if ( currentPage > 0 ) {
375+ const newPage = currentPage - 1 ;
376+ setCurrentPage ( newPage ) ;
377+ loadQuery (
378+ { page : newPage , pageSize } ,
379+ { fetchPolicy : 'network-only' }
380+ ) ;
381+ }
382+ } ;
383+
384+ const handleNextPage = ( ) => {
385+ if ( currentPage < numPages - 1 ) {
386+ const newPage = currentPage + 1 ;
387+ setCurrentPage ( newPage ) ;
388+ loadQuery (
389+ { page : newPage , pageSize } ,
390+ { fetchPolicy : 'network-only' }
391+ ) ;
392+ }
393+ } ;
394+
358395 return (
359396 < div style = { { display : 'flex' , flexFlow : 'column' } } >
360397 < h1 > Suppliers</ h1 >
@@ -545,13 +582,30 @@ const SupplierListContent = ({
545582 ) ) }
546583
547584 < div className = "Form" >
548- < div style = { { display : 'flex' } } >
549- < button disabled = { true } > { `<< (Coming Soon)` } </ button >
550- < span style = { { flex : 1 , textAlign : 'center' } } >
551- Page { ( data . suppliers ?. page || 0 ) + 1 } of { data . suppliers ?. numPages || 1 }
585+ < div style = { { display : 'flex' , alignItems : 'center' , gap : '12px' } } >
586+ < button
587+ onClick = { handlePreviousPage }
588+ disabled = { currentPage === 0 }
589+ style = { { minWidth : '100px' } }
590+ >
591+ Previous
592+ </ button >
593+ < span style = { { flex : 1 , textAlign : 'center' , fontWeight : '500' } } >
594+ Page { currentPage + 1 } of { numPages }
552595 </ span >
553- < button disabled = { true } > { `>> (Coming Soon)` } </ button >
596+ < button
597+ onClick = { handleNextPage }
598+ disabled = { currentPage >= numPages - 1 }
599+ style = { { minWidth : '100px' } }
600+ >
601+ Next
602+ </ button >
554603 </ div >
604+ { totalItems > 0 && (
605+ < div style = { { textAlign : 'center' , fontSize : '14px' , color : '#666' , marginTop : '8px' } } >
606+ Showing { Math . min ( currentPage * pageSize + 1 , totalItems ) } - { Math . min ( ( currentPage + 1 ) * pageSize , totalItems ) } of { totalItems } suppliers
607+ </ div >
608+ ) }
555609 </ div >
556610 </ div >
557611 ) ;
0 commit comments