1- import { useMemo , useState } from "react" ;
1+ import { useEffect , useMemo , useState } from "react" ;
2+ import { useForm } from "react-hook-form" ;
23import { useTranslations } from "next-intl" ;
34import { useRouter } from "next/navigation" ;
45import { PaginationType } from "@/interfaces/Pagination" ;
56import { Team } from "@/interfaces/Team" ;
67import Box from "@/components/Box" ;
8+ import InputWrapper from "@/components/InputWrapper" ;
79import Pagination from "@/components/Pagination" ;
810import Table from "@/components/Table" ;
911import DeleteTeamDialog from "@/modules/DeleteTeamDialog" ;
12+ import useDebounce from "@/hooks/useDebounce" ;
1013import useDialog from "@/hooks/useDialog" ;
1114import useGet from "@/hooks/useGet" ;
1215import apis from "@/config/apis" ;
16+ import {
17+ teamSearchDefaultValues ,
18+ teamSearchFilter ,
19+ } from "@/config/forms/teamSearch" ;
1320import { getColumns } from "@/config/tables/teamManagement" ;
1421import { Routes } from "@/consts/routes" ;
1522
@@ -33,6 +40,17 @@ const TeamsList = ({
3340 const [ sort , setSort ] = useState ( { key : "created_at" , direction : "desc" } ) ;
3441 const [ currentPage , setCurrentPage ] = useState ( 1 ) ;
3542
43+ const { control, watch, setValue } = useForm ( {
44+ defaultValues : teamSearchDefaultValues ,
45+ } ) ;
46+
47+ const watchAll = watch ( ) ;
48+ const searchDebounced = useDebounce ( watchAll . search , 500 ) ;
49+
50+ useEffect ( ( ) => {
51+ setCurrentPage ( 1 ) ;
52+ } , [ searchDebounced ] ) ;
53+
3654 const queryParams = new URLSearchParams ( ) ;
3755
3856 queryParams . append ( "sort" , `${ sort . key } :${ sort . direction } ` ) ;
@@ -42,6 +60,10 @@ const TeamsList = ({
4260 queryParams . append ( "is_question_bank" , questionBankStatus ) ;
4361 }
4462
63+ if ( searchDebounced ) {
64+ queryParams . append ( "name" , searchDebounced ) ;
65+ }
66+
4567 queryParams . sort ( ) ;
4668 const qs = queryParams . toString ( ) ;
4769
@@ -87,6 +109,13 @@ const TeamsList = ({
87109
88110 return (
89111 < >
112+ < Box sx = { { p : 0 , mb : 2 , maxWidth : 400 } } >
113+ < InputWrapper
114+ setValue = { setValue }
115+ control = { control }
116+ { ...teamSearchFilter }
117+ />
118+ </ Box >
90119 < Box sx = { { p : 0 , mb : 2 } } >
91120 < Table < Team >
92121 columns = { columns }
0 commit comments