Skip to content

Commit

Permalink
add getTotalPages util function
Browse files Browse the repository at this point in the history
  • Loading branch information
levil664 committed Jul 12, 2024
1 parent d097eff commit f1a0198
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions apps/schools/domains/common/utils/getTotalPages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const getTotalPages = (counts: { [key: string]: { count: number | undefined } }, pageSize: number) => {
return Object.keys(counts).reduce((total, key) => {
return total + Math.ceil((counts[key].count ?? 0) / pageSize) * pageSize
}, 0)
}
8 changes: 5 additions & 3 deletions apps/schools/domains/student/components/studentList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { defaultPaginationTablePage, defaultPaginationTablePageSize } from '@dom
import { scrollToTop } from '@domains/common/utils/scrollInDirection'
import { handlePaginationChange } from '@domains/common/handlers/paginationChange'
import { calculateResults } from '@domains/student/handlers/resultsCalculate'
import { getTotalPages } from '@domains/common/utils/getTotalPages'

export function StudentList() {
const [queryPaginationParams, setQueryPaginationParams] = useState({
Expand Down Expand Up @@ -113,9 +114,10 @@ export function StudentList() {
pagination={{
current: paginationParams.page,
pageSize: paginationParams.pageSize,
total:
Math.ceil((invites?.count ?? 0) / paginationParams.pageSize) * paginationParams.pageSize +
Math.ceil((students?.count ?? 0) / paginationParams.pageSize) * paginationParams.pageSize,
total: getTotalPages(
{ invites: { count: invites?.count }, students: { count: students?.count } },
paginationParams.pageSize,
),
onChange: (page, pageSize) => {
handlePageChange(page, pageSize)
},
Expand Down

0 comments on commit f1a0198

Please sign in to comment.