11"use client" ;
2- import { fetchSubmission , type Submission } from "@/api/fetchIdeas" ;
2+ import { fetchIdeas , ideaType } from "@/api/fetchIdeas" ;
33import { fetchTeams } from "@/api/teams" ;
44import { DataTable } from "@/components/table/data-table" ;
55import { DataTableColumnHeader } from "@/components/table/data-table-column-header" ;
@@ -21,7 +21,7 @@ interface TeamData {
2121 name : string | null ;
2222 numberOfPeople : number ;
2323 roundQualified : number ;
24- submission : Submission | null ;
24+ submission : ideaType | null ;
2525}
2626
2727export default function TeamsIdeasTable ( ) {
@@ -37,74 +37,15 @@ export default function TeamsIdeasTable() {
3737 isLoading : teamsLoading ,
3838 isError : teamsError ,
3939 } = useQuery ( {
40- queryKey : [ "teams " , currentPage , pageLimit ] ,
40+ queryKey : [ "idea " , currentPage , pageLimit ] ,
4141 queryFn : ( ) =>
4242 fetchTeams ( {
4343 limit : pageLimit ,
4444 cursorId : undefined ,
4545 } ) ,
4646 } ) ;
4747
48- const { data : processedData , isLoading : submissionsLoading } = useQuery ( {
49- queryKey : [ "teams-submissions" , teamsData ?. teams ] ,
50- queryFn : async ( ) => {
51- if ( ! teamsData ?. teams ) return [ ] ;
5248
53- const teamsWithSubmissions = await Promise . all (
54- teamsData . teams . map ( async ( team : Team ) => {
55- if ( ! team . ID ) return null ;
56-
57- const submission = await fetchSubmission ( team . ID ) ;
58-
59- return {
60- id : team . ID ,
61- name : team . Name ,
62- numberOfPeople : team . NumberOfPeople ,
63- roundQualified : team . RoundQualified ,
64- submission : submission ,
65- } as TeamData ;
66- } ) ,
67- ) ;
68-
69- return teamsWithSubmissions . filter ( ( team ) : team is TeamData => ! ! team ) ;
70- } ,
71- enabled : ! ! teamsData ?. teams ,
72- } ) ;
73-
74- useEffect ( ( ) => {
75- if ( processedData ) {
76- const tracks = new Set < string > ( ) ;
77- processedData . forEach ( ( team ) => {
78- if ( team . submission ?. track ) {
79- tracks . add ( team . submission . track ) ;
80- }
81- } ) ;
82- setAvailableTracks ( Array . from ( tracks ) ) ;
83- }
84- } , [ processedData ] ) ;
85-
86- useEffect ( ( ) => {
87- if ( ! processedData ) return ;
88-
89- const filtered = processedData . filter ( ( team ) => {
90- const matchesSearch = searchTerm
91- ? ( team . name ?. toLowerCase ( ) . includes ( searchTerm . toLowerCase ( ) ) ??
92- false ) ||
93- ( team . submission ?. title
94- ?. toLowerCase ( )
95- . includes ( searchTerm . toLowerCase ( ) ) ??
96- false )
97- : true ;
98-
99- const matchesTrack = selectedTrack
100- ? team . submission ?. track === selectedTrack
101- : true ;
102-
103- return matchesSearch && matchesTrack ;
104- } ) ;
105-
106- setFilteredData ( filtered ) ;
107- } , [ processedData , searchTerm , selectedTrack ] ) ;
10849
10950 const columns : ColumnDef < TeamData , unknown > [ ] = [
11051 {
@@ -129,37 +70,37 @@ export default function TeamsIdeasTable() {
12970 } ,
13071 {
13172 id : "submissionTitle" ,
132- accessorFn : ( row ) => row . submission ?. title ,
73+ accessorFn : ( row ) => row . submission ?. Title ,
13374 header : ( { column } ) => (
13475 < DataTableColumnHeader column = { column } title = "Submission Title" />
13576 ) ,
13677 cell : ( { row } ) => (
13778 < div className = "max-w-[200px] truncate" >
138- { row . original . submission ?. title ?? "No submission" }
79+ { row . original . submission ?. Title ?? "No submission" }
13980 </ div >
14081 ) ,
14182 } ,
14283 {
14384 id : "submissionDescription" ,
144- accessorFn : ( row ) => row . submission ?. description ,
85+ accessorFn : ( row ) => row . submission ?. Description ,
14586 header : ( { column } ) => (
14687 < DataTableColumnHeader column = { column } title = "Description" />
14788 ) ,
14889 cell : ( { row } ) => (
14990 < div className = "max-w-[300px] truncate" >
150- { row . original . submission ?. description ?? "No description" }
91+ { row . original . submission ?. Description ?? "No description" }
15192 </ div >
15293 ) ,
15394 } ,
15495 {
15596 id : "track" ,
156- accessorFn : ( row ) => row . submission ?. track ,
97+ accessorFn : ( row ) => row . submission ?. Track ,
15798 header : ( { column } ) => (
15899 < DataTableColumnHeader column = { column } title = "Track" />
159100 ) ,
160101 cell : ( { row } ) => (
161102 < div className = "max-w-[200px] truncate" >
162- { row . original . submission ?. track ?? "Unassigned" }
103+ { row . original . submission ?. Track ?? "Unassigned" }
163104 </ div >
164105 ) ,
165106 } ,
0 commit comments