Skip to content

Commit

Permalink
Merge pull request #152 from open-schools/fix/SCHOOL-844/delete-pagin…
Browse files Browse the repository at this point in the history
…ation

Fix/school 844/delete pagination
  • Loading branch information
zavarin-michael authored Jul 19, 2024
2 parents 94e6184 + 74750c8 commit 394655b
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 151 deletions.
23 changes: 1 addition & 22 deletions apps/schools/domains/circle/components/circleList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion apps/schools/domains/common/components/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <RowType, DataItemType>(props: CustomTableProps<RowType, DataItemType>) => {
const {
Expand Down
2 changes: 1 addition & 1 deletion apps/schools/domains/common/components/table/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
Expand Down
26 changes: 3 additions & 23 deletions apps/schools/domains/employee/components/employeeList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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]}
Expand All @@ -72,4 +52,4 @@ export function EmployeeList() {
/>
</>
)
}
}
8 changes: 4 additions & 4 deletions apps/schools/domains/organization/redux/organizationApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ const organizationApi = commonApi.injectEndpoints({
body: data,
}),
}),
getAllStudents: build.query<ReturnedData<GetStudent[]>, AllStudentsData>({
getAllStudents: build.query<ReturnedData<TableTypeStudent[]>, AllStudentsData>({
query: (params) => ({
url: '/organization-management/organizations/students',
method: 'GET',
params: params,
}),
transformResponse: (response: ReturnedData<GetStudent[]>) => {
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
Expand Down Expand Up @@ -182,8 +182,8 @@ const organizationApi = commonApi.injectEndpoints({
}),
transformResponse: (response: ReturnedData<GetCircleInviteStudent[]>) => {
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')
Expand Down
21 changes: 0 additions & 21 deletions apps/schools/domains/query/components/queryList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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]}
Expand Down
60 changes: 4 additions & 56 deletions apps/schools/domains/student/components/studentList/index.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -17,69 +17,28 @@ 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()

const { data: invites, isLoading: isLoadingInvites } = useGetAllStudentInvitationsQuery({
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 (
Expand Down Expand Up @@ -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}
Expand All @@ -133,4 +81,4 @@ export function StudentList() {
/>
</EmptyWrapper>
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface RowType {
}

export interface TableType {
id?: string
id: string
student_name: string
student_phone: string
parent_phone: string
Expand Down
21 changes: 0 additions & 21 deletions apps/schools/domains/ticket/components/ticketList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLInputElement> | string) => void
type HandleChange = (
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -128,18 +119,6 @@ export function TicketList() {
<div className={styles.tableTicketList}>
<Table<RowType, TableType>
loading={isTableLoading}
pagination={{
current: paginationParams.page,
pageSize: paginationParams.pageSize,
total: tickets?.count,
onChange: (page, pageSize) => {
setPaginationParams({
page,
pageSize,
})
scrollToTop()
},
}}
customType={'tableWithoutSearch'}
columnsTitlesAndKeys={[
['Создано', 'created_at'],
Expand Down

0 comments on commit 394655b

Please sign in to comment.