diff --git a/apps/schools/domains/circle/components/circleList/index.tsx b/apps/schools/domains/circle/components/circleList/index.tsx index 9cfadbf3..72321657 100644 --- a/apps/schools/domains/circle/components/circleList/index.tsx +++ b/apps/schools/domains/circle/components/circleList/index.tsx @@ -13,24 +13,15 @@ import EmptyWrapper from '@domains/common/components/containers/EmptyWrapper' import { HighlightText } from '@domains/common/components/table/forming' import { getVarsForAddressColumn } from '@domains/common/utils/geo' import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' -import { defaultPaginationTablePage, defaultPaginationTablePageSize } from '@domains/common/constants/Table' -import { scrollToTop } from '@domains/common/utils/scrollInDirection' -import {useQueryState} from "next-usequerystate"; +import { useQueryState } from 'next-usequerystate' export function CircleList() { const [searchRequestText, setSearchRequestText] = useQueryState('search') const { organizationId } = useOrganization() - const [paginationParams, setPaginationParams] = useState({ - page: defaultPaginationTablePage, - pageSize: defaultPaginationTablePageSize, - }) - const { data: circles, isFetching: isFetching } = useGetAllCirclesQuery({ organization_id: organizationId, or_search: createSearchTextForRequest(searchRequestText || '', searchStudentsColumns), - page: paginationParams.page, - page_size: paginationParams.pageSize, }) return ( @@ -61,18 +52,6 @@ export function CircleList() { ['Адрес', 'address'], ['Кол-во принятых заявок', 'accepted_count'], ]} - pagination={{ - current: paginationParams.page, - pageSize: paginationParams.pageSize, - total: circles?.count, - onChange: (page, pageSize) => { - setPaginationParams({ - page, - pageSize, - }) - scrollToTop() - }, - }} data={circles} isLoading={isFetching} mainRoute={RoutePath[AppRoutes.CIRCLE_LIST]} diff --git a/apps/schools/domains/circle/components/currentCircle/index.tsx b/apps/schools/domains/circle/components/currentCircle/index.tsx index bb89ebfd..dd0398c2 100644 --- a/apps/schools/domains/circle/components/currentCircle/index.tsx +++ b/apps/schools/domains/circle/components/currentCircle/index.tsx @@ -25,7 +25,7 @@ import { getVarsForAddressColumn } from '@domains/common/utils/geo' import { StatusesEnum } from '@domains/common/constants/Enums' import { ErrorType } from '@store/commonApi' import { AppRoutes, DynamicAppRoutes, DynamicRoutePath, RoutePath } from '@domains/common/constants/routerEnums' -import {useQueryState} from "next-usequerystate"; +import { useQueryState } from 'next-usequerystate' const CurrentCircle = () => { const [isModalVisible, setIsModalVisible] = useState(false) diff --git a/apps/schools/domains/common/components/table/index.tsx b/apps/schools/domains/common/components/table/index.tsx index 108f962e..f01e598b 100644 --- a/apps/schools/domains/common/components/table/index.tsx +++ b/apps/schools/domains/common/components/table/index.tsx @@ -9,7 +9,7 @@ import { typeTable } from '@domains/common/constants/Table' import { CustomTableProps } from '@domains/common/components/table/interfaces' import { calculateAverageWidth } from '@domains/common/utils/calculateAverageWidth' import { ColumnType } from 'antd/lib/table/interface' -import { useQueryState } from "next-usequerystate"; +import { useQueryState } from 'next-usequerystate' export const Table = (props: CustomTableProps) => { const { diff --git a/apps/schools/domains/common/components/table/interfaces.ts b/apps/schools/domains/common/components/table/interfaces.ts index 332235ab..54ba112b 100644 --- a/apps/schools/domains/common/components/table/interfaces.ts +++ b/apps/schools/domains/common/components/table/interfaces.ts @@ -3,7 +3,7 @@ import { ReturnedData } from '@domains/common/redux/interfaces' import { TableProps } from 'antd' import { ColumnFilterItem } from 'antd/lib/table/interface' import { Key } from 'antd/es/table/interface' -import {Options} from "next-usequerystate"; +import { Options } from 'next-usequerystate' export interface CustomFieldsProps { [key: string]: React.FC<{ diff --git a/apps/schools/domains/employee/components/employeeList/index.tsx b/apps/schools/domains/employee/components/employeeList/index.tsx index 1621d49e..5024dec1 100644 --- a/apps/schools/domains/employee/components/employeeList/index.tsx +++ b/apps/schools/domains/employee/components/employeeList/index.tsx @@ -11,24 +11,16 @@ import { GetListEmployee } from '@domains/employee/redux/interfaces' import { RowType } from '@domains/employee/components/employeeList/interfaces' import { searchColumns } from '@domains/employee/components/employeeList/constants' import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' -import { defaultPaginationTablePage, defaultPaginationTablePageSize } from '@domains/common/constants/Table' -import { scrollToTop } from '@domains/common/utils/scrollInDirection' import { useQueryState } from 'next-usequerystate' +import { scrollToTop } from '@domains/common/utils/scrollInDirection' export function EmployeeList() { - const { organizationId } = useOrganization() const [searchRequest, setSearchRequest] = useQueryState('search') - - const [paginationParams, setPaginationParams] = useState({ - page: defaultPaginationTablePage, - pageSize: defaultPaginationTablePageSize, - }) + const { organizationId } = useOrganization() const { data, isFetching } = useGetAllEmployeesQuery({ organization: organizationId, or_search: createSearchTextForRequest(searchRequest || '', searchColumns), - page: paginationParams.page, - page_size: paginationParams.pageSize, }) return ( @@ -51,18 +43,6 @@ export function EmployeeList() { ['Должность', 'position'], ['Телефон', 'phone'], ]} - pagination={{ - current: paginationParams.page, - pageSize: paginationParams.pageSize, - total: data?.count, - onChange: (page, pageSize) => { - setPaginationParams({ - page, - pageSize, - }); - scrollToTop(); - }, - }} data={data} isLoading={isFetching} mainRoute={RoutePath[AppRoutes.EMPLOYEE_LIST]} @@ -72,4 +52,4 @@ export function EmployeeList() { /> ) -} \ No newline at end of file +} diff --git a/apps/schools/domains/organization/redux/organizationApi.ts b/apps/schools/domains/organization/redux/organizationApi.ts index 2307d8a5..bd63a421 100644 --- a/apps/schools/domains/organization/redux/organizationApi.ts +++ b/apps/schools/domains/organization/redux/organizationApi.ts @@ -65,7 +65,7 @@ const organizationApi = commonApi.injectEndpoints({ body: data, }), }), - getAllStudents: build.query, AllStudentsData>({ + getAllStudents: build.query, AllStudentsData>({ query: (params) => ({ url: '/organization-management/organizations/students', method: 'GET', @@ -73,7 +73,7 @@ const organizationApi = commonApi.injectEndpoints({ }), transformResponse: (response: ReturnedData) => { return mapReturnedData(response, (query) => { - const transformedQuery = structuredClone(query) as unknown as TableTypeStudent + const transformedQuery = structuredClone(query) transformedQuery.id = query.id transformedQuery.student_name = query.name transformedQuery.student_phone = query.student_profile.phone @@ -182,8 +182,8 @@ const organizationApi = commonApi.injectEndpoints({ }), transformResponse: (response: ReturnedData) => { return mapReturnedData(response, (query) => { - const transformedQuery = structuredClone(query) as unknown as TableTypeStudent - transformedQuery.id = query.body.id + const transformedQuery = structuredClone(query) + transformedQuery.id = query.body.id || '' transformedQuery.student_name = query.body.name transformedQuery.student_phone = query.additional.phone transformedQuery.parent_phone = query.recipient.parent_phones.replaceAll(',', '\n') diff --git a/apps/schools/domains/query/components/queryList/index.tsx b/apps/schools/domains/query/components/queryList/index.tsx index b554fe46..61be9087 100644 --- a/apps/schools/domains/query/components/queryList/index.tsx +++ b/apps/schools/domains/query/components/queryList/index.tsx @@ -20,8 +20,6 @@ import { useQueryState } from 'next-usequerystate' import { parseAsArrayOf, parseAsString } from 'next-usequerystate' import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums' import SearchInput from '@domains/common/components/searchInput' -import { defaultPaginationTablePage, defaultPaginationTablePageSize } from '@domains/common/constants/Table' -import { scrollToTop } from '@domains/common/utils/scrollInDirection' export function QueryList() { const { organizationId } = useOrganization() @@ -70,16 +68,9 @@ export function QueryList() { return items }, [analytics, statuses]) - const [paginationParams, setPaginationParams] = useState({ - page: defaultPaginationTablePage, - pageSize: defaultPaginationTablePageSize, - }) - const { data: queries, isFetching: isQueriesFetching } = useGetAllJoinCircleQueriesQuery({ circle__organization__id: organizationId, or_search: createSearchTextForRequest(searchRequest || '', searchStudentsColumns), - page: paginationParams.page, - page_size: paginationParams.pageSize, }) const countAllQueries = useMemo( @@ -127,18 +118,6 @@ export function QueryList() { ['Телефон родителя', 'parent_phone'], ['Кружок', 'circle_name'], ]} - pagination={{ - current: paginationParams.page, - pageSize: paginationParams.pageSize, - total: queries?.count, - onChange: (page, pageSize) => { - setPaginationParams({ - page, - pageSize, - }) - scrollToTop() - }, - }} data={queries} isLoading={isQueriesFetching} mainRoute={RoutePath[AppRoutes.QUERY_LIST]} diff --git a/apps/schools/domains/student/components/studentList/index.tsx b/apps/schools/domains/student/components/studentList/index.tsx index 619998ab..e64a9ac1 100644 --- a/apps/schools/domains/student/components/studentList/index.tsx +++ b/apps/schools/domains/student/components/studentList/index.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useState } from 'react' +import React, { useCallback, useEffect, useState } from 'react' import { Typography } from 'antd' import router from 'next/router' import styles from './styles/styles.module.scss' @@ -17,20 +17,9 @@ 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' -import { useQueryState } from "next-usequerystate" +import { useQueryState } from 'next-usequerystate' export function StudentList() { - const [queryPaginationParams, setQueryPaginationParams] = useState({ - invites: { - page: defaultPaginationTablePage, - pageSize: defaultPaginationTablePageSize, - }, - students: { - page: defaultPaginationTablePage, - pageSize: defaultPaginationTablePageSize, - }, - }) - const [searchRequestText, setSearchRequestText] = useQueryState('search') const { organizationId } = useOrganization() @@ -38,48 +27,18 @@ export function StudentList() { circle__organization__id: organizationId, status: StatusesEnum.SENT, or_search: createSearchTextForRequest(searchRequestText || '', searchInvitesColumns), - page: queryPaginationParams.invites.page, - page_size: queryPaginationParams.invites.pageSize, }) const { data: students, isFetching: isFetchingStudents } = useGetAllStudentsQuery({ circle__organization: organizationId, or_search: createSearchTextForRequest(searchRequestText || '', searchStudentsColumns), - page: queryPaginationParams.students.page, - page_size: queryPaginationParams.students.pageSize, - }) - - const [paginationParams, setPaginationParams] = useState({ - page: defaultPaginationTablePage, - pageSize: defaultPaginationTablePageSize, }) - const resultsCalculate = useCallback( - () => calculateResults(paginationParams, { invites, students }), - [paginationParams, invites, students], - ) - const data = { count: (invites?.count ?? 0) + (students?.count ?? 0), next: invites?.next ?? '', previous: invites?.previous ?? '', - results: resultsCalculate(), - } - - const handlePageChange = (newPage: number, newPageSize: number) => { - handlePaginationChange( - setPaginationParams, - setQueryPaginationParams as any, - { - invites: invites?.count, - students: students?.count, - }, - newPage, - newPageSize, - defaultPaginationTablePage, - defaultPaginationTablePageSize, - scrollToTop, - ) + results: [...((invites?.results ?? []) as unknown as TableType[]), ...(students?.results ?? [])], } return ( @@ -112,17 +71,6 @@ export function StudentList() { ['Телефон обучающегося', 'student_phone'], ['Телефон родителя', 'parent_phone'], ]} - pagination={{ - current: paginationParams.page, - pageSize: paginationParams.pageSize, - total: getTotalPages( - { invites: { count: invites?.count }, students: { count: students?.count } }, - paginationParams.pageSize, - ), - onChange: (page, pageSize) => { - handlePageChange(page, pageSize) - }, - }} filterFields={['circle_name']} data={data} isLoading={isLoadingInvites || isFetchingStudents} @@ -133,4 +81,4 @@ export function StudentList() { /> ) -} \ No newline at end of file +} diff --git a/apps/schools/domains/student/components/studentList/interfaces.ts b/apps/schools/domains/student/components/studentList/interfaces.ts index 36c22cb9..0ba393b7 100644 --- a/apps/schools/domains/student/components/studentList/interfaces.ts +++ b/apps/schools/domains/student/components/studentList/interfaces.ts @@ -7,7 +7,7 @@ export interface RowType { } export interface TableType { - id?: string + id: string student_name: string student_phone: string parent_phone: string diff --git a/apps/schools/domains/ticket/components/ticketList/index.tsx b/apps/schools/domains/ticket/components/ticketList/index.tsx index f74acbc3..595f0cd7 100644 --- a/apps/schools/domains/ticket/components/ticketList/index.tsx +++ b/apps/schools/domains/ticket/components/ticketList/index.tsx @@ -19,8 +19,6 @@ import Image from 'next/image' import dot from '@public/icons/dot.svg' import SearchInput from '@domains/common/components/searchInput' import { FilterValue, SorterResult, TableCurrentDataSource } from 'antd/es/table/interface' -import { defaultPaginationTablePage, defaultPaginationTablePageSize } from '@domains/common/constants/Table' -import { scrollToTop } from '@domains/common/utils/scrollInDirection' type HandleInputChange = (text: React.ChangeEvent | string) => void type HandleChange = ( @@ -70,16 +68,9 @@ export function TicketList() { } as BubbleFilterListItem } - const [paginationParams, setPaginationParams] = useState({ - page: defaultPaginationTablePage, - pageSize: defaultPaginationTablePageSize, - }) - const { data: tickets, isFetching: isTicketsFetching } = useGetAllTicketsQuery({ organization_id: organizationId, or_search: createSearchTextForRequest(searchRequest || '', searchTicketsColumns), - page: paginationParams.page, - page_size: paginationParams.pageSize, }) useEffect(() => { @@ -128,18 +119,6 @@ export function TicketList() {
loading={isTableLoading} - pagination={{ - current: paginationParams.page, - pageSize: paginationParams.pageSize, - total: tickets?.count, - onChange: (page, pageSize) => { - setPaginationParams({ - page, - pageSize, - }) - scrollToTop() - }, - }} customType={'tableWithoutSearch'} columnsTitlesAndKeys={[ ['Создано', 'created_at'],