@@ -9,12 +9,17 @@ import { fetchUsers } from "@/api/user";
99import loading from "@/assets/images/loading.gif" ;
1010import { Button } from "@/components/ui/button" ;
1111import { type User } from "@/data/schema" ;
12- import { useQuery } from "@tanstack/react-query" ;
12+ import { useQuery , useQueryClient } from "@tanstack/react-query" ;
1313import Image from "next/image" ;
14- import { useState } from "react" ;
14+ import { useEffect , useState } from "react" ;
1515import { useDebounce } from "use-debounce" ;
16+ import SelectGender from "@/components/select-gender" ;
17+ import toast from "react-hot-toast" ;
1618
1719export default function Users ( ) {
20+ const queryClient = useQueryClient ( ) ;
21+
22+ const [ gender , setGender ] = useState < string > ( "" ) ;
1823 const [ cursorHistory , setCursorHistory ] = useState < string [ ] > ( [ ] ) ;
1924 const [ currentCursor , setCurrentCursor ] = useState < string | undefined > (
2025 undefined ,
@@ -34,6 +39,7 @@ export default function Users() {
3439 limit : pageLimit ,
3540 cursorId : currentCursor ,
3641 name : nameDebounce ,
42+ gender : gender ,
3743 } ) ,
3844 placeholderData : ( previousData ) => previousData ,
3945 // enabled: !!debouncedSearch,
@@ -54,12 +60,16 @@ export default function Users() {
5460 setCurrentCursor ( prevCursor ?? undefined ) ; // Move to previous page
5561 }
5662 } ;
57-
63+ useEffect ( ( ) => {
64+ void queryClient . invalidateQueries ( {
65+ queryKey : [ "users" ] ,
66+ } ) ;
67+ } , [ gender ] ) ;
5868 const onClick = async ( ) => {
5969 try {
6070 const blob = await downloadCSV ( ) ;
6171
62- const url = window . URL . createObjectURL ( blob ) ;
72+ const url = window . URL . createObjectURL ( blob ) ;
6373 const a = document . createElement ( "a" ) ;
6474 a . href = url ;
6575 a . download = "users.csv" ; // Set the filename for the downloaded file
@@ -84,6 +94,7 @@ export default function Users() {
8494 onChange = { ( e ) => setTheName ( e . target . value ) }
8595 type = "text"
8696 />
97+ < SelectGender gender = { gender } setGender = { setGender } > </ SelectGender >
8798 < Button onClick = { onClick } > Download CSV </ Button >
8899 </ div >
89100
0 commit comments