Skip to content

Commit 19f7d93

Browse files
committed
2 parents b1f3384 + 4c18f0b commit 19f7d93

5 files changed

Lines changed: 18 additions & 15 deletions

File tree

src/api/teams.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export const fetchTeams = async ({
3838
}
3939
};
4040

41-
export const setTeamRound = async (id: string, round: string) => {
41+
export const setTeamRound = async (id: string, round: number) => {
4242
try{
43-
const response = await axios.put<TeamsResponse>("/admin/team/rounds",{id, role: round});
43+
const response = await axios.put<TeamsResponse>("/admin/team/rounds",{id, round_qualified: round});
4444
return response.data
4545
}
4646
catch(err){

src/components/changeRound.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@ import {
99
SelectLabel,
1010
} from "@/components/ui/select";
1111
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";
12+
import { useState } from "react";
13+
import { type Leaderboard } from "@/api/leaderboard";
1514
import { setTeamRound } from "@/api/teams";
1615

17-
interface SelectCellProps {
18-
row: Row<Leaderboard>;
19-
}
2016

21-
function ChangeRound({ row }: SelectCellProps) {
17+
18+
function ChangeRound({ id }: {id:string}) {
2219
const queryClient = useQueryClient();
2320

2421
const [selectedValue, setSelectedValue] = useState<string>("");
2522

2623
const mutation = useMutation({
2724
mutationFn: (data: { id: string; round: string }) => {
28-
return setTeamRound(data.id, data.round);
25+
return setTeamRound(data.id, Number(data.round));
2926
},
3027
onSuccess: async () => {
3128
await queryClient.invalidateQueries({
@@ -35,12 +32,12 @@ function ChangeRound({ row }: SelectCellProps) {
3532
});
3633
//So, even if mutation.mutate fails its gonna set to new value. Fix should be ez
3734
const handleValueChange = (round: string) => {
38-
mutation.mutate({ id: row.original.team_id, round: round });
35+
mutation.mutate({ id: id, round: round });
3936
setSelectedValue(round); // Update local state immediately
4037
};
4138

4239
return (
43-
<div className="w-full">
40+
<div className="flex items-center justify-center">
4441
<Select
4542
value={selectedValue}
4643
disabled={mutation.isPending}

src/components/columns/LeaderBoardCol.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const columns: ColumnDef<z.infer<typeof leaderboardUserSchema>>[] = [
2424
},
2525
{
2626
accessorKey: "ID",
27-
header: "Set Round",
28-
cell: ({ row }) => <ChangeRound row={row} />,
27+
header: "Change Round",
28+
cell: ({ row }) => <ChangeRound id={row.original.team_id} />,
2929
},
3030
{
3131
accessorKey: "View",

src/components/columns/TeamCol.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { type Team } from "@/data/schema";
88
import { Button } from "@/components/ui/button";
99
import { useRouter } from "next/navigation";
1010
import { ArrowRight } from "lucide-react";
11+
import ChangeRound from "../changeRound";
1112

1213
const TeamActions = ({ teamId }: { teamId: string | null }) => {
1314
const router = useRouter();
@@ -62,6 +63,11 @@ const columns: ColumnDef<Team>[] = [
6263
return <TeamActions teamId={row.original.ID} />;
6364
},
6465
},
66+
{
67+
accessorKey: "ID",
68+
header: "Change Round",
69+
cell: ({ row }) => <ChangeRound id={row.original.ID} />,
70+
},
6571
];
6672

6773
export default columns;

src/data/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const usersResponseSchema = z.object({
4646

4747

4848
export const teamSchema = z.object({
49-
ID: z.string().nullable(),
49+
ID: z.string(),
5050
Name: z.string().nullable(),
5151
NumberOfPeople: z.number(),
5252
RoundQualified: z.number(),

0 commit comments

Comments
 (0)