Skip to content

Commit 06c11ae

Browse files
finally unscrewed the idea a little bit
1 parent 8eaa0a6 commit 06c11ae

2 files changed

Lines changed: 54 additions & 74 deletions

File tree

src/api/fetchIdeas.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,39 +40,39 @@ export type ideaType = z.infer<typeof ideaSchema>;
4040

4141
export type ideaResponseType = z.infer<typeof ideasResponseSchema>;
4242

43-
export const fetchIdeas = async (id?: number) => {
43+
44+
45+
46+
47+
export const fetchIdeas = async ({
48+
limit,
49+
cursorId,
50+
name,
51+
}: {
52+
limit: number;
53+
cursorId?: string;
54+
name?: string;}
55+
) => {
4456
try {
57+
const params = new URLSearchParams({ limit: String(limit) });
58+
59+
if (name) {
60+
params.append("name", name);
61+
} else if (cursorId) {
62+
params.append("cursor", cursorId);
63+
}
64+
4565
const response = await axios.get<ideaResponseType>(`admin/ideas`);
4666
const parsedResponse = ideasResponseSchema.parse(response.data);
47-
console.log(parsedResponse);
48-
return parsedResponse.data;
49-
} catch (err) {
67+
console.log(parsedResponse.data);
68+
const nextCursor = 2;
69+
70+
return {
71+
idea: parsedResponse.data,
72+
nextCursor,
73+
};
74+
} catch (err) {
5075
console.log(err);
5176
throw err;
5277
}
5378
};
54-
55-
// export const fetchSubmission = async (
56-
// teamId: string,
57-
// ): Promise<Submission | null> => {
58-
// try {
59-
// const response = await axios.get(`/submission/get`, {
60-
// params: { teamId },
61-
// headers: {
62-
// "Content-Type": "application/json",
63-
// },
64-
// withCredentials: true,
65-
// });
66-
67-
// const parsedResponse = submissionResponseSchema.parse(response.data);
68-
69-
// if (parsedResponse.status === "success" && parsedResponse.data) {
70-
// return parsedResponse.data;
71-
// }
72-
73-
// return null;
74-
// } catch (error) {
75-
// console.error(`Error fetching submission for team ${teamId}:`, error);
76-
// return null;
77-
// }
78-
// };

src/app/idea/page.tsx

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,105 +16,83 @@ import { useQuery } from "@tanstack/react-query";
1616
import { type ColumnDef } from "@tanstack/react-table";
1717
import { useEffect, useState } from "react";
1818

19-
interface TeamData {
20-
id: string;
21-
name: string | null;
22-
numberOfPeople: number;
23-
roundQualified: number;
24-
submission: ideaType | null;
25-
}
26-
2719
export default function TeamsIdeasTable() {
2820
const [pageLimit, setPageLimit] = useState(10);
2921
const [searchTerm, setSearchTerm] = useState("");
3022
const [currentPage, setCurrentPage] = useState(0);
3123
const [selectedTrack, setSelectedTrack] = useState<string>("");
32-
const [filteredData, setFilteredData] = useState<TeamData[]>([]);
3324
const [availableTracks, setAvailableTracks] = useState<string[]>([]);
3425

3526
const {
36-
data: teamsData,
37-
isLoading: teamsLoading,
38-
isError: teamsError,
27+
data: ideasData,
28+
isLoading: ideasLoading,
29+
isError: ideasError,
3930
} = useQuery({
4031
queryKey: ["idea", currentPage, pageLimit],
4132
queryFn: () =>
42-
fetchTeams({
33+
fetchIdeas({
4334
limit: pageLimit,
4435
cursorId: undefined,
4536
}),
4637
});
4738

48-
49-
50-
const columns: ColumnDef<TeamData, unknown>[] = [
51-
{
52-
accessorKey: "name",
53-
header: ({ column }) => (
54-
<DataTableColumnHeader column={column} title="Team Name" />
55-
),
56-
cell: ({ row }) => (
57-
<div className="max-w-[200px] truncate font-medium">
58-
{row.getValue("name") ?? "Unnamed Team"}
59-
</div>
60-
),
61-
},
39+
const columns: ColumnDef<ideaType, unknown>[] = [
6240
{
6341
accessorKey: "numberOfPeople",
6442
header: ({ column }) => (
6543
<DataTableColumnHeader column={column} title="Team Size" />
6644
),
6745
cell: ({ row }) => (
68-
<div className="text-center">{row.getValue("numberOfPeople")}</div>
46+
<div className="text-center">{row.original.TeamID}</div>
6947
),
7048
},
7149
{
7250
id: "submissionTitle",
73-
accessorFn: (row) => row.submission?.Title,
51+
accessorFn: (row) => row.Title,
7452
header: ({ column }) => (
7553
<DataTableColumnHeader column={column} title="Submission Title" />
7654
),
7755
cell: ({ row }) => (
7856
<div className="max-w-[200px] truncate">
79-
{row.original.submission?.Title ?? "No submission"}
57+
{row.original.Title ?? "No submission"}
8058
</div>
8159
),
8260
},
8361
{
8462
id: "submissionDescription",
85-
accessorFn: (row) => row.submission?.Description,
63+
accessorFn: (row) => row.Description,
8664
header: ({ column }) => (
8765
<DataTableColumnHeader column={column} title="Description" />
8866
),
8967
cell: ({ row }) => (
9068
<div className="max-w-[300px] truncate">
91-
{row.original.submission?.Description ?? "No description"}
69+
{row.original.Description ?? "No description"}
9270
</div>
9371
),
9472
},
9573
{
9674
id: "track",
97-
accessorFn: (row) => row.submission?.Track,
75+
accessorFn: (row) => row.Track,
9876
header: ({ column }) => (
9977
<DataTableColumnHeader column={column} title="Track" />
10078
),
10179
cell: ({ row }) => (
10280
<div className="max-w-[200px] truncate">
103-
{row.original.submission?.Track ?? "Unassigned"}
81+
{row.original.Track ?? "Unassigned"}
10482
</div>
10583
),
10684
},
10785
];
10886

109-
if (teamsLoading || submissionsLoading) {
87+
if (ideasLoading) {
11088
return (
11189
<div className="flex justify-center p-8">
11290
<div className="text-lg">Loading teams and submissions...</div>
11391
</div>
11492
);
11593
}
11694

117-
if (teamsError) {
95+
if (ideasError) {
11896
return (
11997
<div className="flex justify-center p-8">
12098
<div className="text-lg text-red-500">Error loading teams data</div>
@@ -125,7 +103,7 @@ export default function TeamsIdeasTable() {
125103
return (
126104
<Card className="w-full">
127105
<CardHeader>
128-
<CardTitle>Teams & Submissions Dashboard</CardTitle>
106+
<CardTitle>Ideas </CardTitle>
129107
</CardHeader>
130108
<CardContent>
131109
<div className="mb-6 flex flex-wrap gap-4">
@@ -155,14 +133,16 @@ export default function TeamsIdeasTable() {
155133
</SelectContent>
156134
</Select>
157135
</div>
158-
<DataTable
159-
columns={columns}
160-
data={filteredData}
161-
handleNextPage={() => setCurrentPage((prev) => prev + 1)}
162-
handlePrevPage={() => setCurrentPage((prev) => prev - 1)}
163-
setPageLimit={setPageLimit}
164-
pageLimit={pageLimit}
165-
/>
136+
{ideasData?.idea && (
137+
<DataTable
138+
columns={columns}
139+
data={ideasData?.idea}
140+
handleNextPage={() => setCurrentPage((prev) => prev + 1)}
141+
handlePrevPage={() => setCurrentPage((prev) => prev - 1)}
142+
setPageLimit={setPageLimit}
143+
pageLimit={pageLimit}
144+
/>
145+
)}
166146
</CardContent>
167147
</Card>
168148
);

0 commit comments

Comments
 (0)