From 66e785673fab42c03d9592e06a83fb8d0721726c Mon Sep 17 00:00:00 2001 From: nenichv Date: Thu, 11 Jul 2024 19:42:07 +0500 Subject: [PATCH 1/4] add search parameter in query/ticket/employee tables --- .../components/employeeList/index.tsx | 23 ++++++++++++------- .../query/components/queryList/index.tsx | 18 ++++++++++----- .../ticket/components/ticketList/index.tsx | 22 +++++++++++------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/apps/schools/domains/employee/components/employeeList/index.tsx b/apps/schools/domains/employee/components/employeeList/index.tsx index 7247578b..91c9b6be 100644 --- a/apps/schools/domains/employee/components/employeeList/index.tsx +++ b/apps/schools/domains/employee/components/employeeList/index.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, {useEffect, useState} from 'react' import { Typography } from 'antd' import router from 'next/router' import styles from './styles/styles.module.scss' @@ -13,10 +13,15 @@ import { searchColumns } from '@domains/employee/components/employeeList/constan 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' export function EmployeeList() { - const [searchRequestText, setSearchRequestText] = useState('') const { organizationId } = useOrganization() + const [searchRequest, setSearchRequest] = useQueryState('search') + + useEffect(() => { + localStorage.setItem('search', searchRequest) + }, [searchRequest]); const [paginationParams, setPaginationParams] = useState({ page: defaultPaginationTablePage, @@ -25,11 +30,13 @@ export function EmployeeList() { const { data, isFetching } = useGetAllEmployeesQuery({ organization: organizationId, - or_search: createSearchTextForRequest(searchRequestText, searchColumns), + or_search: createSearchTextForRequest(searchRequest || '', searchColumns), page: paginationParams.page, page_size: paginationParams.pageSize, }) + const searchRequestText = localStorage.getItem('search') ? localStorage.getItem('search') : searchRequest; + return ( <>
@@ -58,17 +65,17 @@ export function EmployeeList() { setPaginationParams({ page, pageSize, - }) - scrollToTop() + }); + scrollToTop(); }, }} data={data} isLoading={isFetching} mainRoute={RoutePath[AppRoutes.EMPLOYEE_LIST]} searchFields={searchColumns} - searchRequestText={searchRequestText} - setSearchRequestText={setSearchRequestText} + searchRequestText={searchRequestText || ''} + setSearchRequestText={(text) => setSearchRequest(text)} /> ) -} +} \ No newline at end of file diff --git a/apps/schools/domains/query/components/queryList/index.tsx b/apps/schools/domains/query/components/queryList/index.tsx index e8153aff..743526b4 100644 --- a/apps/schools/domains/query/components/queryList/index.tsx +++ b/apps/schools/domains/query/components/queryList/index.tsx @@ -25,9 +25,15 @@ import { scrollToTop } from '@domains/common/utils/scrollInDirection' export function QueryList() { const { organizationId } = useOrganization() - const [searchRequestText, setSearchRequestText] = useState('') + const [searchRequest, setSearchRequest] = useQueryState('search') const [isTableLoading, setIsTableLoading] = useState(false) + useEffect(() => { + localStorage.setItem('search', searchRequest) + }, [searchRequest]); + + const searchRequestText = localStorage.getItem('search') ? localStorage.getItem('search') : searchRequest; + const [statuses, setStatuses] = useQueryState( 'statuses', parseAsArrayOf(parseAsString).withOptions({ @@ -77,7 +83,7 @@ export function QueryList() { const { data: queries, isFetching: isQueriesFetching } = useGetAllJoinCircleQueriesQuery({ circle__organization__id: organizationId, - or_search: createSearchTextForRequest(searchRequestText, searchStudentsColumns), + or_search: createSearchTextForRequest(searchRequestText || '', searchStudentsColumns), page: paginationParams.page, page_size: paginationParams.pageSize, }) @@ -96,7 +102,7 @@ export function QueryList() { const handleSearchChange = useCallback((value: string) => { setIsTableLoading(true) setTimeout(() => { - setSearchRequestText(value) + setSearchRequest(value) }, 1000) }, []) @@ -107,7 +113,7 @@ export function QueryList() { pageTitle={'Заявки'} data={queries} isLoading={isQueriesFetching} - searchTrigger={searchRequestText} + searchTrigger={searchRequestText || ''} >
Заявки @@ -202,8 +208,8 @@ export function QueryList() { }, }} sortFields={['created_at']} - searchRequestText={searchRequestText} - setSearchRequestText={setSearchRequestText} + searchRequestText={searchRequestText || ''} + setSearchRequestText={(text) => setSearchRequest(text)} onChange={(pagination, filters, sorter) => { const localStatuses = [...(filters['status'] ?? [])] as string[] setStatuses(localStatuses.length === 0 ? null : localStatuses) diff --git a/apps/schools/domains/ticket/components/ticketList/index.tsx b/apps/schools/domains/ticket/components/ticketList/index.tsx index c8fbfc49..6fb47ec6 100644 --- a/apps/schools/domains/ticket/components/ticketList/index.tsx +++ b/apps/schools/domains/ticket/components/ticketList/index.tsx @@ -32,9 +32,15 @@ type HandleChange = ( export function TicketList() { const [inputText, setInputText] = useState('') - const [searchRequestText, setSearchRequestText] = useState('') const [isTableLoading, setIsTableLoading] = useState(false) const { organizationId } = useOrganization() + const [searchRequest, setSearchRequest] = useQueryState('search') + + useEffect(() => { + localStorage.setItem('search', searchRequest) + }, [searchRequest]); + + const searchRequestText = localStorage.getItem('search') ? localStorage.getItem('search') : searchRequest; const [statuses, setStatuses] = useQueryState( 'statuses', @@ -77,7 +83,7 @@ export function TicketList() { const { data: tickets, isFetching: isTicketsFetching } = useGetAllTicketsQuery({ organization_id: organizationId, - or_search: createSearchTextForRequest(searchRequestText, searchTicketsColumns), + or_search: createSearchTextForRequest(searchRequestText || '', searchTicketsColumns), page: paginationParams.page, page_size: paginationParams.pageSize, }) @@ -94,17 +100,17 @@ export function TicketList() { setIsTableLoading(true) setInputText(text) setTimeout(() => { - setSearchRequestText(text) + setSearchRequest(text) }, 1000) } else { setIsTableLoading(true) setInputText(text.target.value) setTimeout(() => { - setSearchRequestText(text.target.value) + setSearchRequest(text.target.value) }, 1000) } }, - [setIsTableLoading, setInputText, setSearchRequestText], + [setIsTableLoading, setInputText, setSearchRequest], ) const handleChange: HandleChange = useCallback( @@ -122,7 +128,7 @@ export function TicketList() { pageTitle={'Обращения'} data={tickets} isLoading={isTicketsFetching} - searchTrigger={searchRequestText} + searchTrigger={searchRequestText || ''} >
Обращения @@ -209,8 +215,8 @@ export function TicketList() { }, }} sortFields={['created_at']} - searchRequestText={searchRequestText} - setSearchRequestText={setSearchRequestText} + searchRequestText={searchRequestText || ''} + setSearchRequestText={(text) => setSearchRequest(text)} onChange={handleChange} />
From ea2d023e2ee967db2f4c818d79b27388f3af7ea6 Mon Sep 17 00:00:00 2001 From: nenichv Date: Fri, 12 Jul 2024 18:14:37 +0500 Subject: [PATCH 2/4] delete localstorage, add query state in input search --- .../domains/common/components/table/index.tsx | 5 +++-- .../employee/components/employeeList/index.tsx | 10 ++-------- .../domains/query/components/queryList/index.tsx | 12 +++--------- .../domains/ticket/components/ticketList/index.tsx | 12 +++--------- 4 files changed, 11 insertions(+), 28 deletions(-) diff --git a/apps/schools/domains/common/components/table/index.tsx b/apps/schools/domains/common/components/table/index.tsx index 1e7d1ffb..108f962e 100644 --- a/apps/schools/domains/common/components/table/index.tsx +++ b/apps/schools/domains/common/components/table/index.tsx @@ -9,6 +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"; export const Table = (props: CustomTableProps) => { const { @@ -64,7 +65,7 @@ export const Table = (props: CustomTableProps([]) const router = useRouter() @@ -134,7 +135,7 @@ export const Table = (props: CustomTableProps diff --git a/apps/schools/domains/employee/components/employeeList/index.tsx b/apps/schools/domains/employee/components/employeeList/index.tsx index 91c9b6be..1621d49e 100644 --- a/apps/schools/domains/employee/components/employeeList/index.tsx +++ b/apps/schools/domains/employee/components/employeeList/index.tsx @@ -1,4 +1,4 @@ -import React, {useEffect, useState} from 'react' +import React, { useState } from 'react' import { Typography } from 'antd' import router from 'next/router' import styles from './styles/styles.module.scss' @@ -19,10 +19,6 @@ export function EmployeeList() { const { organizationId } = useOrganization() const [searchRequest, setSearchRequest] = useQueryState('search') - useEffect(() => { - localStorage.setItem('search', searchRequest) - }, [searchRequest]); - const [paginationParams, setPaginationParams] = useState({ page: defaultPaginationTablePage, pageSize: defaultPaginationTablePageSize, @@ -35,8 +31,6 @@ export function EmployeeList() { page_size: paginationParams.pageSize, }) - const searchRequestText = localStorage.getItem('search') ? localStorage.getItem('search') : searchRequest; - return ( <>
@@ -73,7 +67,7 @@ export function EmployeeList() { isLoading={isFetching} mainRoute={RoutePath[AppRoutes.EMPLOYEE_LIST]} searchFields={searchColumns} - searchRequestText={searchRequestText || ''} + searchRequestText={searchRequest || ''} setSearchRequestText={(text) => setSearchRequest(text)} /> diff --git a/apps/schools/domains/query/components/queryList/index.tsx b/apps/schools/domains/query/components/queryList/index.tsx index 743526b4..3e1176fa 100644 --- a/apps/schools/domains/query/components/queryList/index.tsx +++ b/apps/schools/domains/query/components/queryList/index.tsx @@ -28,12 +28,6 @@ export function QueryList() { const [searchRequest, setSearchRequest] = useQueryState('search') const [isTableLoading, setIsTableLoading] = useState(false) - useEffect(() => { - localStorage.setItem('search', searchRequest) - }, [searchRequest]); - - const searchRequestText = localStorage.getItem('search') ? localStorage.getItem('search') : searchRequest; - const [statuses, setStatuses] = useQueryState( 'statuses', parseAsArrayOf(parseAsString).withOptions({ @@ -83,7 +77,7 @@ export function QueryList() { const { data: queries, isFetching: isQueriesFetching } = useGetAllJoinCircleQueriesQuery({ circle__organization__id: organizationId, - or_search: createSearchTextForRequest(searchRequestText || '', searchStudentsColumns), + or_search: createSearchTextForRequest(searchRequest || '', searchStudentsColumns), page: paginationParams.page, page_size: paginationParams.pageSize, }) @@ -113,7 +107,7 @@ export function QueryList() { pageTitle={'Заявки'} data={queries} isLoading={isQueriesFetching} - searchTrigger={searchRequestText || ''} + searchTrigger={searchRequest || ''} >
Заявки @@ -208,7 +202,7 @@ export function QueryList() { }, }} sortFields={['created_at']} - searchRequestText={searchRequestText || ''} + searchRequestText={searchRequest || ''} setSearchRequestText={(text) => setSearchRequest(text)} onChange={(pagination, filters, sorter) => { const localStatuses = [...(filters['status'] ?? [])] as string[] diff --git a/apps/schools/domains/ticket/components/ticketList/index.tsx b/apps/schools/domains/ticket/components/ticketList/index.tsx index 6fb47ec6..9f1e85c2 100644 --- a/apps/schools/domains/ticket/components/ticketList/index.tsx +++ b/apps/schools/domains/ticket/components/ticketList/index.tsx @@ -36,12 +36,6 @@ export function TicketList() { const { organizationId } = useOrganization() const [searchRequest, setSearchRequest] = useQueryState('search') - useEffect(() => { - localStorage.setItem('search', searchRequest) - }, [searchRequest]); - - const searchRequestText = localStorage.getItem('search') ? localStorage.getItem('search') : searchRequest; - const [statuses, setStatuses] = useQueryState( 'statuses', parseAsArrayOf(parseAsString).withOptions({ @@ -83,7 +77,7 @@ export function TicketList() { const { data: tickets, isFetching: isTicketsFetching } = useGetAllTicketsQuery({ organization_id: organizationId, - or_search: createSearchTextForRequest(searchRequestText || '', searchTicketsColumns), + or_search: createSearchTextForRequest(searchRequest || '', searchTicketsColumns), page: paginationParams.page, page_size: paginationParams.pageSize, }) @@ -128,7 +122,7 @@ export function TicketList() { pageTitle={'Обращения'} data={tickets} isLoading={isTicketsFetching} - searchTrigger={searchRequestText || ''} + searchTrigger={searchRequest || ''} >
Обращения @@ -215,7 +209,7 @@ export function TicketList() { }, }} sortFields={['created_at']} - searchRequestText={searchRequestText || ''} + searchRequestText={searchRequest || ''} setSearchRequestText={(text) => setSearchRequest(text)} onChange={handleChange} /> From 99a54f79d9f11627ddb048c12f94e2c92d25582c Mon Sep 17 00:00:00 2001 From: nenichv Date: Mon, 15 Jul 2024 14:41:24 +0500 Subject: [PATCH 3/4] fix --- .../domains/circle/components/circleList/index.tsx | 11 ++++++----- .../circle/components/currentCircle/index.tsx | 9 +++++---- .../domains/common/components/searchInput/index.tsx | 7 ++++--- .../domains/common/components/table/interfaces.ts | 6 +++++- .../domains/query/components/queryList/index.tsx | 4 +--- .../student/components/studentList/index.tsx | 13 +++++++------ .../domains/ticket/components/ticketList/index.tsx | 8 ++------ 7 files changed, 30 insertions(+), 28 deletions(-) diff --git a/apps/schools/domains/circle/components/circleList/index.tsx b/apps/schools/domains/circle/components/circleList/index.tsx index 9c23ba0d..9cfadbf3 100644 --- a/apps/schools/domains/circle/components/circleList/index.tsx +++ b/apps/schools/domains/circle/components/circleList/index.tsx @@ -15,9 +15,10 @@ 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"; export function CircleList() { - const [searchRequestText, setSearchRequestText] = useState('') + const [searchRequestText, setSearchRequestText] = useQueryState('search') const { organizationId } = useOrganization() const [paginationParams, setPaginationParams] = useState({ @@ -27,7 +28,7 @@ export function CircleList() { const { data: circles, isFetching: isFetching } = useGetAllCirclesQuery({ organization_id: organizationId, - or_search: createSearchTextForRequest(searchRequestText, searchStudentsColumns), + or_search: createSearchTextForRequest(searchRequestText || '', searchStudentsColumns), page: paginationParams.page, page_size: paginationParams.pageSize, }) @@ -41,7 +42,7 @@ export function CircleList() { data={circles} isLoading={isFetching} handleRunTask={() => router.push(RoutePath[AppRoutes.CIRCLE_CREATE])} - searchTrigger={searchRequestText} + searchTrigger={searchRequestText || ''} >
Кружки @@ -94,8 +95,8 @@ export function CircleList() { }, }} customWidths={[60, 25, 15]} - searchRequestText={searchRequestText} - setSearchRequestText={setSearchRequestText} + searchRequestText={searchRequestText || ''} + setSearchRequestText={(text) => setSearchRequestText(text)} rowClassName={styles.tableRowPointer} /> diff --git a/apps/schools/domains/circle/components/currentCircle/index.tsx b/apps/schools/domains/circle/components/currentCircle/index.tsx index 48cbcb25..bb89ebfd 100644 --- a/apps/schools/domains/circle/components/currentCircle/index.tsx +++ b/apps/schools/domains/circle/components/currentCircle/index.tsx @@ -25,10 +25,11 @@ 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"; const CurrentCircle = () => { const [isModalVisible, setIsModalVisible] = useState(false) - const [searchRequestText, setSearchRequestText] = useState('') + const [searchRequestText, setSearchRequestText] = useQueryState('search') const [mutation, isDeleteFinished] = useDeleteCircleMutation() const uuid = getUuidFromUrl() const router = useRouter() @@ -40,7 +41,7 @@ const CurrentCircle = () => { const { data: circle, error: circleError } = useGetCircleQuery({ circle_id: uuid[0] }) const { data: students, isLoading } = useGetCircleStudentsQuery({ circle_id: uuid[0], - or_search: createSearchTextForRequest(searchRequestText, searchColumns), + or_search: createSearchTextForRequest(searchRequestText || '', searchColumns), }) const { data: queryData } = useGetCurrentCircleQuery({ circle_id: uuid[0], organization_id: organizationId }) @@ -135,8 +136,8 @@ const CurrentCircle = () => { isLoading={isLoading} needNumbering={true} searchFields={['student_name', 'student_phone', 'parent_names', 'parent_phones']} - searchRequestText={searchRequestText} - setSearchRequestText={setSearchRequestText} + searchRequestText={searchRequestText || ''} + setSearchRequestText={(text) => setSearchRequestText(text)} />
diff --git a/apps/schools/domains/common/components/searchInput/index.tsx b/apps/schools/domains/common/components/searchInput/index.tsx index 93986b3c..054a158b 100644 --- a/apps/schools/domains/common/components/searchInput/index.tsx +++ b/apps/schools/domains/common/components/searchInput/index.tsx @@ -1,14 +1,15 @@ -import React, { useState, ChangeEvent } from 'react' +import React, { ChangeEvent } from 'react' import { Input } from '@domains/common/components/input' import { CloseCircleOutlined, SearchOutlined } from '@ant-design/icons' import styles from './styles/styles.module.scss' +import { useQueryState } from 'next-usequerystate' interface SearchInputProps { onSearchChange: (value: string) => void } const SearchInput: React.FC = ({ onSearchChange }) => { - const [inputText, setInputText] = useState('') + const [inputText, setInputText] = useQueryState('search') const handleInputChange = (event: ChangeEvent) => { const value = event.target.value @@ -21,7 +22,7 @@ const SearchInput: React.FC = ({ onSearchChange }) => { onChange={handleInputChange} customType={'inputSearch'} placeholder={'Поиск'} - value={inputText} + value={inputText || ''} children={ <> diff --git a/apps/schools/domains/common/components/table/interfaces.ts b/apps/schools/domains/common/components/table/interfaces.ts index 268282eb..332235ab 100644 --- a/apps/schools/domains/common/components/table/interfaces.ts +++ b/apps/schools/domains/common/components/table/interfaces.ts @@ -3,6 +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"; export interface CustomFieldsProps { [key: string]: React.FC<{ @@ -30,7 +31,10 @@ export interface CustomTableProps extends TableProps customFields?: CustomFieldsProps searchRequestText: string needNumbering?: boolean - setSearchRequestText: React.Dispatch> + setSearchRequestText: ( + value: string | ((old: string | null) => string | null) | null, + options?: Options | undefined, + ) => Promise mainRoute: string sortFields?: string[] customFilterFields?: CustomFilterFieldsProps diff --git a/apps/schools/domains/query/components/queryList/index.tsx b/apps/schools/domains/query/components/queryList/index.tsx index 3e1176fa..b554fe46 100644 --- a/apps/schools/domains/query/components/queryList/index.tsx +++ b/apps/schools/domains/query/components/queryList/index.tsx @@ -95,9 +95,7 @@ export function QueryList() { const handleSearchChange = useCallback((value: string) => { setIsTableLoading(true) - setTimeout(() => { - setSearchRequest(value) - }, 1000) + setSearchRequest(value) }, []) return ( diff --git a/apps/schools/domains/student/components/studentList/index.tsx b/apps/schools/domains/student/components/studentList/index.tsx index f5af871a..633da4d0 100644 --- a/apps/schools/domains/student/components/studentList/index.tsx +++ b/apps/schools/domains/student/components/studentList/index.tsx @@ -14,15 +14,16 @@ import EmptyWrapper from '@domains/common/components/containers/EmptyWrapper' 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"; export function StudentList() { - const [searchRequestText, setSearchRequestText] = useState('') + 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), + or_search: createSearchTextForRequest(searchRequestText || '', searchInvitesColumns), }) const [paginationParams, setPaginationParams] = useState({ @@ -32,7 +33,7 @@ export function StudentList() { const { data: students, isFetching: isFetchingStudents } = useGetAllStudentsQuery({ circle__organization: organizationId, - or_search: createSearchTextForRequest(searchRequestText, searchStudentsColumns), + or_search: createSearchTextForRequest(searchRequestText || '', searchStudentsColumns), page: paginationParams.page, page_size: paginationParams.pageSize, }) @@ -75,7 +76,7 @@ export function StudentList() { data={data} isLoading={isFetchingStudents || isLoadingInvites} handleRunTask={() => router.push(RoutePath[AppRoutes.STUDENT_CREATE])} - searchTrigger={searchRequestText} + searchTrigger={searchRequestText || ''} >
Обучающиеся @@ -113,8 +114,8 @@ export function StudentList() { isLoading={isLoadingInvites || isFetchingStudents} mainRoute={RoutePath[AppRoutes.STUDENT_LIST]} searchFields={['student_name', 'student_phone', 'parent_phone', 'circle_name']} - searchRequestText={searchRequestText} - setSearchRequestText={setSearchRequestText} + searchRequestText={searchRequestText || ''} + setSearchRequestText={(text) => setSearchRequestText(text)} /> ) diff --git a/apps/schools/domains/ticket/components/ticketList/index.tsx b/apps/schools/domains/ticket/components/ticketList/index.tsx index 9f1e85c2..f74acbc3 100644 --- a/apps/schools/domains/ticket/components/ticketList/index.tsx +++ b/apps/schools/domains/ticket/components/ticketList/index.tsx @@ -93,15 +93,11 @@ export function TicketList() { if (typeof text === 'string') { setIsTableLoading(true) setInputText(text) - setTimeout(() => { - setSearchRequest(text) - }, 1000) + setSearchRequest(text) } else { setIsTableLoading(true) setInputText(text.target.value) - setTimeout(() => { - setSearchRequest(text.target.value) - }, 1000) + setSearchRequest(text.target.value) } }, [setIsTableLoading, setInputText, setSearchRequest], From 77cdc8be5555d2af2e6e8d18740d13e5f403be79 Mon Sep 17 00:00:00 2001 From: nenichv Date: Wed, 17 Jul 2024 11:12:48 +0500 Subject: [PATCH 4/4] fix conflict --- .../student/components/studentList/index.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/schools/domains/student/components/studentList/index.tsx b/apps/schools/domains/student/components/studentList/index.tsx index f035c9a2..619998ab 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, useEffect, useState } from 'react' +import React, { useCallback, useState } from 'react' import { Typography } from 'antd' import router from 'next/router' import styles from './styles/styles.module.scss' @@ -17,6 +17,7 @@ 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" export function StudentList() { const [queryPaginationParams, setQueryPaginationParams] = useState({ @@ -30,20 +31,20 @@ export function StudentList() { }, }) - const [searchRequestText, setSearchRequestText] = useState('') + 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), + 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), + or_search: createSearchTextForRequest(searchRequestText || '', searchStudentsColumns), page: queryPaginationParams.students.page, page_size: queryPaginationParams.students.pageSize, }) @@ -90,7 +91,7 @@ export function StudentList() { data={data} isLoading={isFetchingStudents || isLoadingInvites} handleRunTask={() => router.push(RoutePath[AppRoutes.STUDENT_CREATE])} - searchTrigger={searchRequestText} + searchTrigger={searchRequestText || ''} >
Обучающиеся @@ -127,9 +128,9 @@ export function StudentList() { isLoading={isLoadingInvites || isFetchingStudents} mainRoute={RoutePath[AppRoutes.STUDENT_LIST]} searchFields={['student_name', 'student_phone', 'parent_phone', 'circle_name']} - searchRequestText={searchRequestText} - setSearchRequestText={setSearchRequestText} + searchRequestText={searchRequestText || ''} + setSearchRequestText={(text) => setSearchRequestText(text)} /> ) -} +} \ No newline at end of file