Skip to content

Commit 8eaa0a6

Browse files
unscrewed up ideas a little bit
1 parent 21cbfbb commit 8eaa0a6

4 files changed

Lines changed: 70 additions & 92 deletions

File tree

src/api/fetchIdeas.ts

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,71 @@ const submissionSchema = z.object({
88
github_link: z.string().nullable(),
99
figma_link: z.string().nullable(),
1010
other_link: z.string().nullable(),
11-
team_id: z.string()
11+
team_id: z.string(),
1212
});
1313

1414
const submissionResponseSchema = z.object({
1515
status: z.string(),
16-
data: submissionSchema.nullable()
16+
data: submissionSchema.nullable(),
1717
});
1818

1919
export type Submission = z.infer<typeof submissionSchema>;
20+
2021
export type SubmissionResponse = z.infer<typeof submissionResponseSchema>;
2122

22-
export const fetchSubmission = async (teamId: string): Promise<Submission | null> => {
23+
const ideaSchema = z.object({
24+
ID: z.string(), // UUID format for IDs
25+
Title: z.string(),
26+
Description: z.string(),
27+
Track: z.string(),
28+
TeamID: z.string(),
29+
IsSelected: z.boolean(),
30+
CreatedAt: z.string(), // ISO 8601 date string
31+
UpdatedAt: z.string(), // ISO 8601 date string
32+
});
33+
34+
export const ideasResponseSchema = z.object({
35+
status: z.string(), // Ensures the status is always "success"
36+
message: z.string(),
37+
data: z.array(ideaSchema),
38+
});
39+
export type ideaType = z.infer<typeof ideaSchema>;
40+
41+
export type ideaResponseType = z.infer<typeof ideasResponseSchema>;
42+
43+
export const fetchIdeas = async (id?: number) => {
2344
try {
24-
const response = await axios.get(`/submission/get`, {
25-
params: { teamId },
26-
headers: {
27-
'Content-Type': 'application/json',
28-
},
29-
withCredentials: true
30-
});
31-
32-
const parsedResponse = submissionResponseSchema.parse(response.data);
33-
34-
if (parsedResponse.status === "success" && parsedResponse.data) {
35-
return parsedResponse.data;
36-
}
37-
38-
return null;
39-
} catch (error) {
40-
console.error(`Error fetching submission for team ${teamId}:`, error);
41-
return null;
45+
const response = await axios.get<ideaResponseType>(`admin/ideas`);
46+
const parsedResponse = ideasResponseSchema.parse(response.data);
47+
console.log(parsedResponse);
48+
return parsedResponse.data;
49+
} catch (err) {
50+
console.log(err);
51+
throw err;
4252
}
43-
};
53+
};
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/api/fetchTeamDetails.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,6 @@ export const fetchTeamDetails = async ({ uuid }: { uuid: string }) => {
9292
console.log(err);
9393
throw err;
9494
}
95-
};
95+
};
96+
97+

src/api/leaderboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const fetchLeaderboard = async ({
4848
params.append("cursor", cursorId);
4949
}
5050

51-
const url = `admin/users?${params.toString()}`;
51+
const url = `admin/leaderboard?${params.toString()}`;
5252

5353
const response = await axios.get<LeaderboardResponse>(url);
5454

src/app/idea/page.tsx

Lines changed: 9 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use client";
2-
import { fetchSubmission, type Submission } from "@/api/fetchIdeas";
2+
import { fetchIdeas, ideaType } from "@/api/fetchIdeas";
33
import { fetchTeams } from "@/api/teams";
44
import { DataTable } from "@/components/table/data-table";
55
import { 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

2727
export 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

Comments
 (0)