From f1a0198e93b72a4e0d28b34f36c6523203be8909 Mon Sep 17 00:00:00 2001 From: lev tarasov <56757711+levil664@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:50:57 +0500 Subject: [PATCH] add getTotalPages util function --- apps/schools/domains/common/utils/getTotalPages.ts | 5 +++++ .../domains/student/components/studentList/index.tsx | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 apps/schools/domains/common/utils/getTotalPages.ts diff --git a/apps/schools/domains/common/utils/getTotalPages.ts b/apps/schools/domains/common/utils/getTotalPages.ts new file mode 100644 index 00000000..7ebaea31 --- /dev/null +++ b/apps/schools/domains/common/utils/getTotalPages.ts @@ -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) +} diff --git a/apps/schools/domains/student/components/studentList/index.tsx b/apps/schools/domains/student/components/studentList/index.tsx index aa6fdfa5..f035c9a2 100644 --- a/apps/schools/domains/student/components/studentList/index.tsx +++ b/apps/schools/domains/student/components/studentList/index.tsx @@ -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({ @@ -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) },