Skip to content

refactor: add reusable pagination hook and refactor components#1089

Merged
dmortal merged 3 commits intomainfrom
da/contractorListPagination
Feb 13, 2026
Merged

refactor: add reusable pagination hook and refactor components#1089
dmortal merged 3 commits intomainfrom
da/contractorListPagination

Conversation

@dmortal
Copy link
Contributor

@dmortal dmortal commented Feb 13, 2026

Summary

This PR introduces a reusable usePagination hook that centralizes pagination state management and extracts pagination metadata from API response headers. Previously, pagination logic was duplicated across multiple components with the same patterns for page navigation, items-per-page control, and metadata extraction.

Changes

  • Added usePagination hook that manages pagination state and provides a getPaginationProps helper
  • Refactored 5 components to use the new hook:
    • LocationsList
    • ContractorList
    • PaymentsList
    • EmployeeList
    • PayrollConfiguration
  • Eliminated ~50 lines of duplicated pagination logic across components
  • Standardized pagination metadata extraction from response headers

Testing

Manual testing:

  • Verified pagination works correctly in all refactored components
  • Tested page navigation (first, previous, next, last)
  • Tested items-per-page selector
  • Confirmed total count and page count display correctly

Run unit tests:

npm run test -- --run src/hooks/usePagination/usePagination.test.ts

@dmortal dmortal marked this pull request as ready for review February 13, 2026 20:43
Copilot AI review requested due to automatic review settings February 13, 2026 20:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a reusable usePagination hook to eliminate duplicated pagination logic across multiple components. The hook centralizes pagination state management (currentPage, itemsPerPage) and provides a getPaginationProps helper that extracts metadata from API response headers and returns all necessary props for the PaginationControl component.

Changes:

  • Added usePagination hook with comprehensive test coverage
  • Refactored 5 components (LocationsList, ContractorList, PaymentsList, EmployeeList, PayrollConfiguration) to use the new hook
  • Eliminated ~50 lines of duplicated pagination state and handler logic

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/hooks/usePagination/usePagination.ts New reusable hook managing pagination state and providing getPaginationProps helper
src/hooks/usePagination/usePagination.test.ts Comprehensive test suite covering all hook functionality
src/components/Payroll/PayrollConfiguration/usePayrollConfigurationData.ts Refactored to use usePagination hook, removing manual state management
src/components/Employee/EmployeeList/EmployeeList.tsx Replaced useState-based pagination with usePagination hook
src/components/Contractor/Payments/PaymentsList/PaymentsListPresentation.tsx Added pagination prop to presentation component
src/components/Contractor/Payments/PaymentsList/PaymentsList.tsx Integrated usePagination hook and passed props to presentation
src/components/Contractor/ContractorList/useContractorList.ts Simplified by using usePagination instead of manual state
src/components/Company/Locations/LocationsList/LocationsList.tsx Refactored to use usePagination hook

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

itemsPerPage,
getPaginationProps,
}
}
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an index.ts file that exports the hook and its types to follow the pattern established by other hooks in this directory (useForkRef, useOverflowDetection). This would allow imports like 'from @/hooks/usePagination' instead of 'from @/hooks/usePagination/usePagination'.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@jeffredodd jeffredodd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -0,0 +1,59 @@
import { useState } from 'react'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic hook idea! 😆

@dmortal dmortal enabled auto-merge (squash) February 13, 2026 21:53
@dmortal dmortal merged commit 2590900 into main Feb 13, 2026
11 checks passed
@dmortal dmortal deleted the da/contractorListPagination branch February 13, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants