Skip to content

Commit 4aa6088

Browse files
Merge remote-tracking branch 'refs/remotes/origin/main'
2 parents fcfc111 + 1ca1910 commit 4aa6088

16 files changed

Lines changed: 144 additions & 103 deletions

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/downloadCSV.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import instance from "./axiosConfig";
22

3-
export const downloadCSV = async (): Promise<Blob> => {
3+
export const downloadCSV = async ({what}: {what:string}): Promise<Blob> => {
44
try {
5-
const response = await instance.get<Blob>(`/admin/usercsv`, {
5+
const response = await instance.get<Blob>(`/admin/${what}`, {
66
withCredentials: true,
77
responseType: "blob",
88
});

src/api/fetchIdeas.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,29 @@ export const fetchIdeas = async ({
5353
limit: number;
5454
cursorId?: string;
5555
name?: string;
56-
track?: string;
56+
track?: number;
5757
}) => {
5858
try {
5959
const params = new URLSearchParams({ limit: String(limit) });
60-
60+
61+
6162
if (name) {
62-
params.append("name", name);
63+
params.append("title", name);
6364
} else if (cursorId) {
6465
params.append("cursor", cursorId);
6566
}
67+
else if(track){
68+
params.append("track", String(track))
69+
}
6670
const url =
67-
track !== ""
68-
? `admin/ideas/${track}?${params.toString()}`
71+
(track || name)
72+
? `admin/ideas/filter?${params.toString()}`
6973
: `admin/ideas?${params.toString()}`;
7074

7175
const response = await axios.get<ideaResponseType>(url);
7276
const parsedResponse = ideasResponseSchema.parse(response.data);
7377
console.log(parsedResponse.data);
74-
78+
console.log(url)
7579
//send in next cursor when data is done
7680
const nextCursor = parsedResponse.data.next_cursor;
7781

@@ -83,4 +87,4 @@ export const fetchIdeas = async ({
8387
console.log(err);
8488
throw err;
8589
}
86-
};
90+
};

src/app/idea/page.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
1717
import { type ColumnDef } from "@tanstack/react-table";
1818
import { useEffect, useState } from "react";
1919
import { ModalTeamIdea } from "./ModalTeamIdea";
20+
import { useDebounce } from "use-debounce";
21+
import CopyLabel from "@/components/CopyLabel";
2022

2123
export default function TeamsIdeasTable() {
2224
const queryClient = useQueryClient();
@@ -28,6 +30,7 @@ export default function TeamsIdeasTable() {
2830
const [pageLimit, setPageLimit] = useState(10);
2931
const [searchTerm, setSearchTerm] = useState("");
3032
const [selectedTrack, setSelectedTrack] = useState<string>("");
33+
const [nameDebounce] = useDebounce(searchTerm, 1000);
3134
const tracks = [
3235
"Media and Entertainment",
3336
"Finance and Fintech",
@@ -41,12 +44,13 @@ export default function TeamsIdeasTable() {
4144
isLoading: ideasLoading,
4245
isError: ideasError,
4346
} = useQuery({
44-
queryKey: ["idea", currentCursor, pageLimit],
47+
queryKey: ["idea", currentCursor, pageLimit, nameDebounce],
4548
queryFn: () =>
4649
fetchIdeas({
4750
limit: pageLimit,
4851
cursorId: currentCursor,
49-
track: selectedTrack,
52+
track: Number(selectedTrack),
53+
name: nameDebounce
5054
}),
5155
});
5256
const handleNextPage = () => {
@@ -76,9 +80,10 @@ export default function TeamsIdeasTable() {
7680
<DataTableColumnHeader column={column} title="Team ID" />
7781
),
7882
cell: ({ row }) => (
79-
<span className="relative block max-w-[100px] cursor-pointer truncate text-ellipsis whitespace-nowrap text-white">
80-
{row.original.TeamID}
81-
</span>
83+
// <span className="relative block max-w-[100px] cursor-pointer truncate text-ellipsis whitespace-nowrap text-white">
84+
// {row.original.TeamID}
85+
// </span>
86+
<CopyLabel label={row.original.TeamID}/>
8287
),
8388
},
8489
{
@@ -184,4 +189,4 @@ export default function TeamsIdeasTable() {
184189
}
185190
</>
186191
);
187-
}
192+
}

src/app/team/[id]/page.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import useToast from "@/lib/toast";
1414
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
1515
import Image from "next/image";
1616
import Link from "next/link";
17-
import { useParams } from "next/navigation";
17+
import { useParams, useRouter } from "next/navigation";
1818
import { useEffect, useState } from "react";
19-
19+
import { BackButton } from "@/components/ui/BackButton";
20+
import { ChevronLeft, Router } from "lucide-react";
2021
export interface Score {
2122
id: string;
2223
team_id: string;
@@ -33,6 +34,7 @@ type ApiError = {
3334
message: string;
3435
};
3536

37+
3638
function ScoreSection({ teamId }: { teamId: string }) {
3739
const [design, setDesign] = useState(0);
3840
const [implementation, setImplementation] = useState(0);
@@ -471,9 +473,15 @@ export default function TheTeam() {
471473
queryKey: ["theTeams", id],
472474
queryFn: () => fetchTeamDetails({ uuid: String(id) }),
473475
});
476+
const router = useRouter();
474477
return (
475478
<>
476479
<div className="mx-auto w-[100%] space-y-4">
480+
<Button variant="outline" size="icon" onClick={()=>{
481+
router.push("/teams")
482+
}}>
483+
<ChevronLeft />
484+
</Button>
477485
{id && <ScoreSection teamId={String(id)} />}
478486
<div
479487
className={`${!teamList ? "h-[70vh]" : "h-auto"} mx-auto w-[100%] rounded-md border bg-black p-4 text-white shadow-lg`}

src/app/teams/page.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ 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";
13+
import { Button } from "@/components/ui/button";
14+
import { downloadCSV } from "@/api/downloadCSV";
1315

1416
export default function Teams() {
1517
const [cursorHistory, setCursorHistory] = useState<string[]>([]);
@@ -20,8 +22,9 @@ export default function Teams() {
2022
const [theName, setTheName] = useState<string>("");
2123
// const queryClient = useQueryClient();
2224
const [selectedTeam, setSelectedTeam] = useState<Team | null>(null);
23-
const [nameDebounce] = useDebounce(theName, 1000);
25+
const [nameDebounce] = useDebounce(theName, 500);
2426
const [open, setOpen] = useState(false);
27+
2528

2629
const queryClient = useQueryClient();
2730

@@ -65,19 +68,41 @@ export default function Teams() {
6568
setSelectedTeam(team);
6669
setOpen(true);
6770
};
71+
const onClick = async () => {
72+
try {
73+
const blob = await downloadCSV({what : "teamcsv"});
74+
75+
const url = window.URL.createObjectURL(blob);
76+
const a = document.createElement("a");
77+
a.href = url;
78+
a.download = "teams.csv"; // Set the filename for the downloaded file
79+
document.body.appendChild(a);
80+
81+
a.click();
82+
83+
window.URL.revokeObjectURL(url);
84+
document.body.removeChild(a);
85+
} catch (err) {
86+
console.error("Error downloading CSV:", err);
87+
alert("Failed to download CSV. Please try again.");
88+
}
89+
};
6890

6991
return (
7092
<>
7193
<div className="p-4">
7294
<div className="mb-4"></div>
73-
<div className="mb-4 flex flex-col items-start">
95+
<div className="mb-4 flex items-center ">
7496
<input
7597
className="bg-gray w-[50%] rounded-md border p-2 text-white"
7698
placeholder="Search"
7799
value={theName}
78100
onChange={(e) => setTheName(e.target.value)}
79101
type="text"
80102
/>
103+
<Button className="ml-2" onClick={onClick}>
104+
Download CSV{" "}
105+
</Button>
81106
</div>
82107
{/* <DataTableUsers users={oosers} columns={userCol} /> */}
83108

src/app/users/page.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ import { useEffect, useState } from "react";
1515
import { useDebounce } from "use-debounce";
1616
import SelectGender from "@/components/select-gender";
1717
import toast from "react-hot-toast";
18-
18+
import { useParams } from "next/navigation";
19+
import { usePathname } from "next/navigation";
1920
export default function Users() {
21+
const pathname = usePathname();
22+
2023
const queryClient = useQueryClient();
2124

2225
const [gender, setGender] = useState<string>("");
@@ -27,7 +30,7 @@ export default function Users() {
2730
const [pageLimit, setPageLimit] = useState<number>(10);
2831
const [theName, setTheName] = useState<string>("");
2932
// const queryClient = useQueryClient();
30-
const [nameDebounce] = useDebounce(theName, 1000);
33+
const [nameDebounce] = useDebounce(theName, 500);
3134
const {
3235
data: userList,
3336
isLoading,
@@ -67,7 +70,7 @@ export default function Users() {
6770
}, [gender]);
6871
const onClick = async () => {
6972
try {
70-
const blob = await downloadCSV();
73+
const blob = await downloadCSV({what : "usercsv"});
7174

7275
const url = window.URL.createObjectURL(blob);
7376
const a = document.createElement("a");
@@ -84,18 +87,21 @@ export default function Users() {
8487
alert("Failed to download CSV. Please try again.");
8588
}
8689
};
90+
8791
return (
8892
<div className="p-4">
89-
<div className="mb-4 flex items-start justify-between">
93+
<div className="mb-4 flex items-center">
9094
<input
91-
className="bg-gray w-[50%] rounded-md border p-2 text-white"
95+
className="bg-gray mr-2 w-[50%] rounded-md border p-2 text-white"
9296
placeholder="Search"
9397
value={theName}
9498
onChange={(e) => setTheName(e.target.value)}
9599
type="text"
96100
/>
97101
<SelectGender gender={gender} setGender={setGender}></SelectGender>
98-
<Button onClick={onClick}>Download CSV </Button>
102+
<Button className="ml-2" onClick={onClick}>
103+
Download CSV{" "}
104+
</Button>
99105
</div>
100106

101107
{isError && <div className="text-red-500">Error fetching user data</div>}

src/components/CopyLabel.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react'
2+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './ui/tooltip'
3+
import { handleCopy } from '@/lib/utils'
4+
5+
const CopyLabel = ({label}:{label:string}) => {
6+
return (
7+
<div>
8+
<TooltipProvider>
9+
<Tooltip>
10+
<TooltipTrigger className="hover:cursor-pointer" asChild>
11+
<span
12+
className="relative block max-w-[120px] cursor-pointer truncate text-ellipsis capitalize whitespace-nowrap text-white"
13+
onClick={() => handleCopy(label)}
14+
>
15+
{label}
16+
</span>
17+
</TooltipTrigger>
18+
<TooltipContent>
19+
<p>Click to copy</p>
20+
</TooltipContent>
21+
</Tooltip>
22+
</TooltipProvider>
23+
</div>
24+
)
25+
}
26+
27+
export default CopyLabel

src/components/columns/TeamCol.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Button } from "@/components/ui/button";
99
import { useRouter } from "next/navigation";
1010
import { ArrowRight } from "lucide-react";
1111
import ChangeRound from "../changeRound";
12+
import CopyLabel from "../CopyLabel";
1213

1314
const TeamActions = ({ teamId }: { teamId: string | null }) => {
1415
const router = useRouter();
@@ -47,7 +48,9 @@ const columns: ColumnDef<Team>[] = [
4748
header: ({ column }) => (
4849
<DataTableColumnHeader column={column} title="Team Code" />
4950
),
50-
cell: ({ row }) => <span>{row.getValue("Code")}</span>,
51+
cell: ({ row }) => {
52+
return <CopyLabel label={row.getValue("Code")} />;
53+
}
5154
},
5255
{
5356
accessorKey: "IsBanned",

0 commit comments

Comments
 (0)