Skip to content

Commit ed1cfc3

Browse files
committed
Team scores added
2 parents 18d07fc + 93d925c commit ed1cfc3

23 files changed

Lines changed: 882 additions & 421 deletions

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"shadcn-ui": "^0.9.4",
4242
"tailwind-merge": "^2.5.2",
4343
"tailwindcss-animate": "^1.0.7",
44+
"use-debounce": "^10.0.4",
4445
"zod": "^3.23.3"
4546
},
4647
"devDependencies": {

pnpm-lock.yaml

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

src/api/auth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const login = async(email: string, password: string) =>{
66
const response = await axios.post('/auth/login', {email, password})
77
return response.data as data;
88
}catch(err){
9+
910
throw err;
1011
}
1112
}

src/api/fetchScores.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,28 @@ interface CreateScoreRequest {
2424
}
2525

2626
export const fetchScores = async (teamId: string) => {
27-
try {
28-
const response = await axios.get<{
29-
status: string;
30-
message: string;
31-
scores: ScoreResponse[];
32-
}>(`panel/getscore/${teamId}`, {
33-
withCredentials: true,
34-
});
35-
return response.data.scores;
36-
} catch (err) {
37-
console.log(err);
38-
throw err;
39-
}
27+
try {
28+
const response = await axios.get<{
29+
status: string;
30+
message: string;
31+
data: {
32+
message: string;
33+
scores: ScoreResponse[];
34+
};
35+
}>(`panel/getscore/${teamId}`, {
36+
withCredentials: true,
37+
});
38+
39+
// The scores are nested inside response.data.data.scores
40+
if (!response.data.data?.scores) {
41+
throw new Error('No scores data received');
42+
}
43+
44+
return response.data.data.scores;
45+
} catch (err) {
46+
console.error('Error fetching scores:', err);
47+
throw err;
48+
}
4049
};
4150

4251
export const createScore = async ({

src/api/fetchTeamDetails.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { TeamsFromSearch, type Team, type TeamResponse } from "@/data/schema";
2+
import { type MainSearch, MainTeamSearchResponse} from "@/data/schema";
3+
4+
import axios from "./axiosConfig";
5+
6+
7+
export const fetchTeamDetails = async ({ uuid }: { uuid: string}) => {
8+
try {
9+
const response = await axios.get<MainSearch>(
10+
`admin/teams/${uuid}`
11+
);
12+
13+
const parsedResponse = MainTeamSearchResponse.parse(response.data)
14+
console.log(parsedResponse)
15+
return parsedResponse.data
16+
} catch (err) {
17+
console.log(err);
18+
throw err;
19+
}
20+
};

src/api/fetchTeams.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,36 @@ import { type Team, type TeamsResponse } from "@/data/schema";
22
import { TeamsResponseSchema } from "@/data/schema";
33
import axios from "./axiosConfig";
44

5-
export const fetchTeams = async ({ page, limit }: { page: number; limit: number }) => {
5+
export const fetchTeams = async ({
6+
limit,
7+
cursorId,
8+
name
9+
}: {
10+
limit: number;
11+
cursorId?: string;
12+
name?:string;
13+
}) => {
614
try {
7-
const response = await axios.get<TeamsResponse>(
8-
`admin/teams?page=${page}&limit=${limit}`
9-
);
15+
16+
const params = new URLSearchParams({ limit: String(limit) });
17+
18+
if (name) {
19+
params.append("name", name);
20+
} else if (cursorId) {
21+
params.append("cursor", cursorId);
22+
}
23+
24+
const url = `admin/teams?${params.toString()}`;
25+
26+
27+
const response = await axios.get<TeamsResponse>(url);
28+
1029
const parsedResponse = TeamsResponseSchema.parse(response.data);
11-
return { teams: parsedResponse.data.teams };
30+
const teams = parsedResponse.data.teams;
31+
const nextCursor = teams!=null ? teams[teams.length - 1]?.ID : null;
32+
33+
return { teams, nextCursor };
34+
// return response.data.data.teams
1235
} catch (err) {
1336
console.log(err);
1437
throw err;

src/api/fetchUsers.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,38 @@ import { usersResponseSchema } from "@/data/schema";
33
import axios from "./axiosConfig";
44

55
export const fetchUsers = async ({
6-
page,
76
limit,
7+
cursorId,
8+
name,
89
}: {
9-
page: number;
1010
limit: number;
11+
cursorId?: string;
12+
name?: string;
1113
}) => {
1214
try {
13-
const response = await axios.get<UserResponse>(
14-
`admin/users?page=${page}&limit=${limit}`
15-
);
15+
const params = new URLSearchParams({ limit: String(limit) });
16+
17+
if (name) {
18+
params.append("name", name);
19+
} else if (cursorId) {
20+
params.append("cursor", cursorId);
21+
}
22+
23+
const url = `admin/users?${params.toString()}`;
24+
25+
const response = await axios.get<UserResponse>(url);
1626

1727
const parsedResponse = usersResponseSchema.parse(response.data);
18-
return {users: parsedResponse.data.users, totalPages: 100};
28+
const users = parsedResponse.data.users;
29+
console.log(users);
30+
const nextCursor = users != null ? users[users.length - 1]?.ID : null;
31+
32+
return {
33+
users,
34+
nextCursor,
35+
};
1936
} catch (err) {
2037
console.log(err);
2138
throw err;
2239
}
23-
};
40+
};

src/app/layout.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
// app/layout.tsx
2+
import { ThemeProvider } from "@/components/theme-provider";
23
import Providers from "@/lib/Providers";
34
import "@/styles/globals.css";
45
import { GeistSans } from "geist/font/sans";
56
import { type Metadata } from "next";
67
import { Toaster } from "react-hot-toast";
7-
import { ThemeProvider } from "@/components/theme-provider";
88

9-
import {
10-
Sheet,
11-
SheetContent,
12-
SheetTrigger,
13-
} from "@/components/ui/sheet";
14-
import { Button } from "@/components/ui/button";
15-
import Link from "next/link";
169
import {
1710
Avatar,
1811
AvatarFallback,
1912
AvatarImage,
2013
} from "@/components/ui/avatar";
14+
import { Button } from "@/components/ui/button";
2115
import {
2216
DropdownMenu,
2317
DropdownMenuContent,
@@ -26,12 +20,19 @@ import {
2620
} from "@/components/ui/dropdown-menu";
2721
import { ScrollArea } from "@/components/ui/scroll-area";
2822
import {
29-
HomeIcon,
30-
UsersIcon,
23+
Sheet,
24+
SheetContent,
25+
SheetTrigger,
26+
} from "@/components/ui/sheet";
27+
import {
3128
GroupIcon,
32-
MenuIcon,
29+
HomeIcon,
3330
LogOutIcon,
31+
MenuIcon,
32+
Search,
33+
UsersIcon
3434
} from "lucide-react";
35+
import Link from "next/link";
3536

3637

3738
export const metadata: Metadata = {
@@ -76,7 +77,7 @@ export default function RootLayout({
7677
<Sidebar />
7778
<div className="flex flex-col flex-1">
7879
<Navbar />
79-
<main className="flex-1 p-8">
80+
<main className=" p-8 overflow-y-scroll">
8081
{children}
8182
</main>
8283
</div>
@@ -91,17 +92,18 @@ export default function RootLayout({
9192

9293
function Sidebar() {
9394
const navigation = [
94-
{ name: "Dashboard", href: "/dashboard", icon: HomeIcon },
95+
// { name: "Dashboard", href: "/dashboard", icon: HomeIcon },
9596
{ name: "Users", href: "/users", icon: UsersIcon },
9697
{ name: "Teams", href: "/teams", icon: GroupIcon },
98+
{name: "Search Team", href: "/team_search", icon: Search}
9799
];
98100

99101
return (
100102
<aside className="border-r border-gray-200 h-full w-64 dark:border-gray-700">
101103
<ScrollArea className="h-full">
102104
<div className="p-4">
103105
<Link href="/" className="text-2xl font-bold mb-6 block">
104-
CodeChef Admin
106+
Devsoc Admin
105107
</Link>
106108
</div>
107109
<nav className="px-2 py-4">

src/app/page.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
"use client"
2+
13
import Image from "next/image";
24
import Link from "next/link";
35
import logo from "../../public/cc-logo.svg";
6+
import { useEffect } from "react";
7+
import { useRouter } from "next/navigation";
48

59
export default function HomePage() {
10+
const router = useRouter();
11+
useEffect(()=>{
12+
router.push("/users")
613

14+
})
715
return (
816
<>
9-
<main className="flex min-h-screen flex-col items-center justify-center p-8">
17+
<main className=" flex min-h-screen flex-col items-center justify-center p-8">
1018
<div className="w-full max-w-xl rounded-lg bg-white p-8 text-center text-black shadow-lg">
1119
<Image
1220
src={logo as HTMLImageElement}

0 commit comments

Comments
 (0)