Skip to content

Commit acf58b4

Browse files
Added upgrade round dialog
1 parent 83c8f36 commit acf58b4

8 files changed

Lines changed: 144 additions & 38 deletions

File tree

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,16 @@ export const fetchTeams = async ({
3636
console.log(err);
3737
throw err;
3838
}
39-
};
39+
};
40+
41+
export const setTeamRound = async (id: string, round: string) => {
42+
try{
43+
const response = await axios.post<TeamsResponse>("/admin/team/rounds",{id, role: round});
44+
return response.data
45+
}
46+
catch(err){
47+
console.log(err);
48+
throw err;
49+
}
50+
51+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ export const fetchUsers = async ({
3838
throw err;
3939
}
4040
};
41+
42+

src/app/idea/page.tsx

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
"use client";
22
import { fetchSubmission, type Submission } from "@/api/fetchIdeas";
3-
import { fetchTeams } from "@/api/fetchTeams";
3+
import { fetchTeams } from "@/api/teams";
44
import { DataTable } from "@/components/table/data-table";
55
import { DataTableColumnHeader } from "@/components/table/data-table-column-header";
66
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
7-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
7+
import {
8+
Select,
9+
SelectContent,
10+
SelectItem,
11+
SelectTrigger,
12+
SelectValue,
13+
} from "@/components/ui/select";
814
import { type Team } from "@/data/schema";
9-
import { useQuery } from '@tanstack/react-query';
15+
import { useQuery } from "@tanstack/react-query";
1016
import { type ColumnDef } from "@tanstack/react-table";
11-
import { useEffect, useState } from 'react';
17+
import { useEffect, useState } from "react";
1218

1319
interface TeamData {
1420
id: string;
@@ -26,33 +32,38 @@ export default function TeamsIdeasTable() {
2632
const [filteredData, setFilteredData] = useState<TeamData[]>([]);
2733
const [availableTracks, setAvailableTracks] = useState<string[]>([]);
2834

29-
const { data: teamsData, isLoading: teamsLoading, isError: teamsError } = useQuery({
35+
const {
36+
data: teamsData,
37+
isLoading: teamsLoading,
38+
isError: teamsError,
39+
} = useQuery({
3040
queryKey: ["teams", currentPage, pageLimit],
31-
queryFn: () => fetchTeams({
32-
limit: pageLimit,
33-
cursorId: undefined
34-
}),
41+
queryFn: () =>
42+
fetchTeams({
43+
limit: pageLimit,
44+
cursorId: undefined,
45+
}),
3546
});
3647

3748
const { data: processedData, isLoading: submissionsLoading } = useQuery({
3849
queryKey: ["teams-submissions", teamsData?.teams],
3950
queryFn: async () => {
4051
if (!teamsData?.teams) return [];
41-
52+
4253
const teamsWithSubmissions = await Promise.all(
4354
teamsData.teams.map(async (team: Team) => {
4455
if (!team.ID) return null;
45-
56+
4657
const submission = await fetchSubmission(team.ID);
47-
58+
4859
return {
4960
id: team.ID,
5061
name: team.Name,
5162
numberOfPeople: team.NumberOfPeople,
5263
roundQualified: team.RoundQualified,
53-
submission: submission
64+
submission: submission,
5465
} as TeamData;
55-
})
66+
}),
5667
);
5768

5869
return teamsWithSubmissions.filter((team): team is TeamData => !!team);
@@ -63,7 +74,7 @@ export default function TeamsIdeasTable() {
6374
useEffect(() => {
6475
if (processedData) {
6576
const tracks = new Set<string>();
66-
processedData.forEach(team => {
77+
processedData.forEach((team) => {
6778
if (team.submission?.track) {
6879
tracks.add(team.submission.track);
6980
}
@@ -75,10 +86,14 @@ export default function TeamsIdeasTable() {
7586
useEffect(() => {
7687
if (!processedData) return;
7788

78-
const filtered = processedData.filter(team => {
89+
const filtered = processedData.filter((team) => {
7990
const matchesSearch = searchTerm
80-
? (team.name?.toLowerCase().includes(searchTerm.toLowerCase()) ?? false) ||
81-
(team.submission?.title?.toLowerCase().includes(searchTerm.toLowerCase()) ?? false)
91+
? (team.name?.toLowerCase().includes(searchTerm.toLowerCase()) ??
92+
false) ||
93+
(team.submission?.title
94+
?.toLowerCase()
95+
.includes(searchTerm.toLowerCase()) ??
96+
false)
8297
: true;
8398

8499
const matchesTrack = selectedTrack
@@ -109,9 +124,7 @@ export default function TeamsIdeasTable() {
109124
<DataTableColumnHeader column={column} title="Team Size" />
110125
),
111126
cell: ({ row }) => (
112-
<div className="text-center">
113-
{row.getValue("numberOfPeople")}
114-
</div>
127+
<div className="text-center">{row.getValue("numberOfPeople")}</div>
115128
),
116129
},
117130
{
@@ -154,15 +167,15 @@ export default function TeamsIdeasTable() {
154167

155168
if (teamsLoading || submissionsLoading) {
156169
return (
157-
<div className="p-8 flex justify-center">
170+
<div className="flex justify-center p-8">
158171
<div className="text-lg">Loading teams and submissions...</div>
159172
</div>
160173
);
161174
}
162175

163176
if (teamsError) {
164177
return (
165-
<div className="p-8 flex justify-center">
178+
<div className="flex justify-center p-8">
166179
<div className="text-lg text-red-500">Error loading teams data</div>
167180
</div>
168181
);
@@ -184,13 +197,15 @@ export default function TeamsIdeasTable() {
184197
/>
185198
<Select
186199
value={selectedTrack ?? "all"}
187-
onValueChange={(value) => setSelectedTrack(value === "all" ? "" : value)}
200+
onValueChange={(value) =>
201+
setSelectedTrack(value === "all" ? "" : value)
202+
}
188203
>
189204
<SelectTrigger className="w-48 p-6">
190205
<SelectValue placeholder="Filter by track" />
191206
</SelectTrigger>
192-
<SelectContent >
193-
<SelectItem value="all" >All Tracks</SelectItem>
207+
<SelectContent>
208+
<SelectItem value="all">All Tracks</SelectItem>
194209
{availableTracks.map((track) => (
195210
<SelectItem key={track} value={track}>
196211
{track}
@@ -202,12 +217,12 @@ export default function TeamsIdeasTable() {
202217
<DataTable
203218
columns={columns}
204219
data={filteredData}
205-
handleNextPage={() => setCurrentPage(prev => prev + 1)}
206-
handlePrevPage={() => setCurrentPage(prev => prev - 1)}
220+
handleNextPage={() => setCurrentPage((prev) => prev + 1)}
221+
handlePrevPage={() => setCurrentPage((prev) => prev - 1)}
207222
setPageLimit={setPageLimit}
208223
pageLimit={pageLimit}
209224
/>
210225
</CardContent>
211226
</Card>
212227
);
213-
}
228+
}

src/app/leaderboard/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use client";
2-
import { columns } from "@/components/columns/LeaderBoardCol";
2+
import columns from "@/components/columns/LeaderBoardCol";
33
import { DataTable } from "@/components/table/data-table";
44
import { fetchLeaderboard, Leaderboard } from "@/api/leaderboard";
55
import loading from "@/assets/images/loading.gif";

src/app/teams/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"use client";
2-
import { DataTable } from "@/components/table/data-table";
32
import teamCol from "@/components/columns/TeamCol";
3+
import { DataTable } from "@/components/table/data-table";
44
// import { useEffect, useMemo, useState } from "react";
55
// import { user } from "@/store/interfaces";
66
// import useToast from "@/lib/toast";
7-
import { useQuery, useQueryClient } from "@tanstack/react-query";
7+
import { fetchTeams } from "@/api/teams";
88
import { type Team } from "@/data/schema";
9-
import { fetchTeams } from "@/api/fetchTeams";
9+
import { useQuery, useQueryClient } from "@tanstack/react-query";
1010
import { useState } from "react";
1111
// import { TeamModal } from "@/components/table/team-modal";
1212
import { useDebounce } from "use-debounce";

src/app/users/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DataTable } from "@/components/table/data-table";
55
// import { user } from "@/store/interfaces";
66
// import useToast from "@/lib/toast";
77
import { downloadCSV } from "@/api/downloadCSV";
8-
import { fetchUsers } from "@/api/fetchUsers";
8+
import { fetchUsers } from "@/api/user";
99
import loading from "@/assets/images/loading.gif";
1010
import { Button } from "@/components/ui/button";
1111
import { type User } from "@/data/schema";

src/components/changeRound.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { useQueryClient, useMutation } from "@tanstack/react-query";
2+
import {
3+
Select,
4+
SelectTrigger,
5+
SelectValue,
6+
SelectContent,
7+
SelectGroup,
8+
SelectItem,
9+
SelectLabel,
10+
} from "@/components/ui/select";
11+
import { type Row } from "@tanstack/react-table"; // Adjust the import based on your setup
12+
import { useEffect, useState } from "react";
13+
import toast from "react-hot-toast";
14+
import { Leaderboard } from "@/api/leaderboard";
15+
import { setTeamRound } from "@/api/teams";
16+
17+
interface SelectCellProps {
18+
row: Row<Leaderboard>;
19+
}
20+
21+
function ChangeRound({ row }: SelectCellProps) {
22+
const queryClient = useQueryClient();
23+
24+
const [selectedValue, setSelectedValue] = useState<string>("");
25+
26+
const mutation = useMutation({
27+
mutationFn: (data: { id: string; round: string }) => {
28+
return setTeamRound(data.id, data.round);
29+
},
30+
onSuccess: async () => {
31+
await queryClient.invalidateQueries({
32+
queryKey: ["leaderboard", "teams"],
33+
});
34+
},
35+
});
36+
//So, even if mutation.mutate fails its gonna set to new value. Fix should be ez
37+
const handleValueChange = (round: string) => {
38+
mutation.mutate({ id: row.original.team_id, round: round });
39+
setSelectedValue(round); // Update local state immediately
40+
};
41+
42+
return (
43+
<div className="w-full">
44+
<Select
45+
value={selectedValue} // Use value for controlled component
46+
disabled={mutation.isPending}
47+
onValueChange={handleValueChange}
48+
>
49+
<SelectTrigger className="m-2 rounded-md border bg-[#121212] p-2">
50+
<SelectValue placeholder={`Select Round`} />
51+
</SelectTrigger>
52+
<SelectContent>
53+
<SelectGroup className="">
54+
<SelectLabel>{`Select Round`}</SelectLabel>
55+
{["1", "2", "3"].map((option) => (
56+
<SelectItem key={option} value={option}>
57+
{option}
58+
</SelectItem>
59+
))}
60+
</SelectGroup>
61+
</SelectContent>
62+
</Select>
63+
</div>
64+
);
65+
}
66+
67+
export default ChangeRound;

src/components/columns/LeaderBoardCol.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,29 @@ import { leaderboardSchema } from "@/api/leaderboard";
33
import { ColumnDef } from "@tanstack/react-table";
44
import { z } from "zod";
55
import ViewScores from "../ViewScores";
6+
import ChangeRound from "../changeRound";
67

7-
export const columns: ColumnDef<z.infer<typeof leaderboardSchema>>[] = [
8+
const columns: ColumnDef<z.infer<typeof leaderboardSchema>>[] = [
89
{
910
accessorKey: "team_name",
1011
header: "Team Name",
1112
},
1213
{
13-
accessorKey: "scores",
14+
accessorKey: "total_score",
1415
header: "Scores",
1516
cell: ({ row }) => <ViewScores row={row} />,
1617
},
1718
{
1819
accessorKey: "total_score",
1920
header: "Final Score",
20-
},
21+
}
22+
,
23+
{
24+
accessorKey: "ID",
25+
header: "Set Round",
26+
cell: ({ row }) => <ChangeRound row={row} />,
27+
28+
}
2129
];
30+
31+
export default columns

0 commit comments

Comments
 (0)