@@ -15,39 +15,39 @@ import loading from "@/assets/images/loading.gif";
1515import Image from "next/image" ;
1616
1717import { type Team } from "@/data/schema" ;
18- import { useQuery } from "@tanstack/react-query" ;
18+ import { useQuery , useQueryClient } from "@tanstack/react-query" ;
1919import { type ColumnDef } from "@tanstack/react-table" ;
2020import { useEffect , useState } from "react" ;
21+ import toast from "react-hot-toast" ;
2122
2223export default function TeamsIdeasTable ( ) {
24+ const queryClient = useQueryClient ( ) ;
2325 const [ cursorHistory , setCursorHistory ] = useState < string [ ] > ( [ ] ) ;
2426 const [ currentCursor , setCurrentCursor ] = useState < string | undefined > (
2527 undefined ,
2628 ) ;
2729
2830 const [ pageLimit , setPageLimit ] = useState ( 10 ) ;
2931 const [ searchTerm , setSearchTerm ] = useState ( "" ) ;
30- const [ currentPage , setCurrentPage ] = useState ( 0 ) ;
3132 const [ selectedTrack , setSelectedTrack ] = useState < string > ( "" ) ;
3233 const tracks = [
3334 "Media and Entertainment" ,
3435 "Finance and Fintech" ,
3536 "Healthcare and Education" ,
36- "Digital Security" ,
37- "Environment and Sustainability" ,
3837 "Environment and Sustainability" ,
38+ "Digital Security" ,
3939 "Open Innovation" ,
4040 ] ;
4141 const {
4242 data : ideasData ,
4343 isLoading : ideasLoading ,
4444 isError : ideasError ,
4545 } = useQuery ( {
46- queryKey : [ "idea" , currentPage , pageLimit ] ,
46+ queryKey : [ "idea" , currentCursor , pageLimit ] ,
4747 queryFn : ( ) =>
4848 fetchIdeas ( {
4949 limit : pageLimit ,
50- cursorId : undefined ,
50+ cursorId : currentCursor ,
5151 track : selectedTrack ,
5252 } ) ,
5353 } ) ;
@@ -58,7 +58,12 @@ export default function TeamsIdeasTable() {
5858 setCurrentCursor ( ideasData . nextCursor ) ; // Move to the next page
5959 }
6060 } ;
61-
61+ useEffect ( ( ) => {
62+ void queryClient . invalidateQueries ( {
63+ queryKey : [ "idea" ] ,
64+ } ) ;
65+ toast . error ( selectedTrack ) ;
66+ } , [ selectedTrack ] ) ;
6267 const handlePrevPage = ( ) => {
6368 if ( cursorHistory . length > 0 ) {
6469 const prevCursor = cursorHistory [ cursorHistory . length - 1 ] ; // Get last cursor
@@ -133,7 +138,7 @@ export default function TeamsIdeasTable() {
133138 if ( ideasError ) {
134139 return (
135140 < div className = "flex justify-center p-8" >
136- < div className = "text-lg text-red-500" > Error loading teams data </ div >
141+ < div className = "text-lg text-red-500" > Error loading ideas </ div >
137142 </ div >
138143 ) ;
139144 }
@@ -153,28 +158,30 @@ export default function TeamsIdeasTable() {
153158 onChange = { ( e ) => setSearchTerm ( e . target . value ) }
154159 />
155160 < Select
156- value = { selectedTrack ?? "all" }
157- onValueChange = { ( value ) =>
158- setSelectedTrack ( value === "all" ? "" : value )
159- }
161+ value = { selectedTrack ?? "" }
162+ onValueChange = { ( value ) => {
163+ setSelectedTrack (
164+ value === "all" ? "" : String ( Number ( value ) ) ,
165+ ) ;
166+ } }
160167 >
161168 < SelectTrigger className = "w-48 p-6" >
162169 < SelectValue placeholder = "Filter by track" />
163170 </ SelectTrigger >
164171 < SelectContent >
165172 < SelectItem value = "all" > All Tracks</ SelectItem >
166173 { tracks . map ( ( track , index ) => (
167- < SelectItem key = { track } value = { String ( index ) } >
174+ < SelectItem key = { track } value = { String ( index + 1 ) } >
168175 { track }
169176 </ SelectItem >
170177 ) ) }
171178 </ SelectContent >
172179 </ Select >
173180 </ div >
174- { ideasData ?. idea && (
181+ { (
175182 < DataTable
176183 columns = { columns }
177- data = { ideasData ?. idea }
184+ data = { ideasData ?. idea . ideas ?? [ ] }
178185 handleNextPage = { handleNextPage }
179186 handlePrevPage = { handlePrevPage }
180187 setPageLimit = { setPageLimit }
0 commit comments