Skip to content

Commit 75169b8

Browse files
things
1 parent 914087d commit 75169b8

18 files changed

Lines changed: 371 additions & 215 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/fetchTeamDetails.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import { TeamsFromSearch, type Team, type TeamResponse } from "@/data/schema";
2-
import { TeamResponseSchema } from "@/data/schema";
2+
import { type MainSearch, MainTeamSearchResponse} from "@/data/schema";
3+
34
import axios from "./axiosConfig";
45

6+
57
export const fetchTeamDetails = async ({ uuid }: { uuid: string}) => {
68
try {
7-
const response1 = await axios.get<TeamResponse>(
9+
const response = await axios.get<MainSearch>(
810
`admin/teams/${uuid}`
911
);
10-
// const response2 = await axios.get(`/admin/teams/leader/${uuid}`)
11-
const response3 = await axios.get<TeamsFromSearch>(`/admin/members/${uuid}`)
12-
console.log(response1.data.data.team )
13-
console.log(response3.data.data.team )
14-
return{
15-
team: response1.data.data.team,
16-
members: response3.data.data.team
17-
}
12+
13+
const parsedResponse = MainTeamSearchResponse.parse(response.data)
14+
console.log(parsedResponse)
15+
return parsedResponse.data
1816
} catch (err) {
1917
console.log(err);
2018
throw err;

src/api/fetchTeams.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@ import axios from "./axiosConfig";
55
export const fetchTeams = async ({
66
limit,
77
cursorId,
8+
name
89
}: {
910
limit: number;
1011
cursorId?: string;
12+
name?:string;
1113
}) => {
1214
try {
1315

14-
const url = cursorId
15-
? `admin/teams?limit=${limit}&cursor=${cursorId}`
16-
: `admin/teams?limit=${limit}`;
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+
1726

1827
const response = await axios.get<TeamsResponse>(url);
1928

src/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export default function RootLayout({
9292

9393
function Sidebar() {
9494
const navigation = [
95-
{ name: "Dashboard", href: "/dashboard", icon: HomeIcon },
95+
// { name: "Dashboard", href: "/dashboard", icon: HomeIcon },
9696
{ name: "Users", href: "/users", icon: UsersIcon },
9797
{ name: "Teams", href: "/teams", icon: GroupIcon },
9898
{name: "Search Team", href: "/team_search", icon: Search}

src/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function HomePage() {
1111
useEffect(()=>{
1212
router.push("/users")
1313

14-
}, [])
14+
})
1515
return (
1616
<>
1717
<main className=" flex min-h-screen flex-col items-center justify-center p-8">

src/app/team_search/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ export default function TeamSearch() {
6464
// data: teamList,
6565
// isLoading,
6666
// isError,
67-
// } = useQuery<TeamResponse>({
67+
// } = useQuery({
6868
// queryKey: ["theTeams", uuid],
6969
// queryFn: () => fetchTeamDetails({ uuid }),
70-
// enabled: !!uuid, // Ensures API call only happens when UUID is entered
70+
// enabled: !!uuid,
7171
// });
7272

73-
return (
73+
return (<></>
7474
// <div className={`${!teamList? "h-[70vh]": "h-auto"} w-[100%] mx-auto p-4 border rounded-md shadow-lg bg-black text-white`}>
7575
// Input field for UUID
7676
// <div className="flex flex-col items-center mb-4">
@@ -115,6 +115,6 @@ export default function TeamSearch() {
115115
// </div>
116116
// )}
117117
// </div>
118-
<></>
118+
119119
);
120120
}

src/app/teams/page.tsx

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,40 @@ import { type Team } from "@/data/schema";
1111
import { fetchTeams } from "@/api/fetchTeams";
1212
import { useState } from "react";
1313
import { TeamModal } from "@/components/table/team-modal";
14+
import { useDebounce } from "use-debounce";
1415

1516
export default function Teams() {
1617
const [cursorHistory, setCursorHistory] = useState<string[]>([]);
17-
const [currentCursor, setCurrentCursor] = useState<string | undefined>(undefined);
18+
const [currentCursor, setCurrentCursor] = useState<string | undefined>(
19+
undefined,
20+
);
21+
const [pageLimit, setPageLimit] = useState<number>(10);
22+
const [theName, setTheName] = useState<string>("");
23+
// const queryClient = useQueryClient();
1824
const [selectedTeam, setSelectedTeam] = useState<Team | null>(null);
25+
const [nameDebounce] = useDebounce(theName, 1000);
1926
const [open, setOpen] = useState(false);
2027

2128
const queryClient = useQueryClient();
2229

2330
const {
24-
data: teamList,
25-
isLoading,
26-
isError,
31+
data: teamList,
32+
isLoading,
33+
isError,
2734
} = useQuery({
28-
queryKey: ["users", currentCursor],
29-
queryFn: () => fetchTeams({limit: 1, cursorId: currentCursor}),
30-
// placeholderData: (previousData) => previousData,
35+
queryKey: ["teams", currentCursor, nameDebounce],
36+
queryFn: () =>
37+
fetchTeams({
38+
limit: pageLimit,
39+
cursorId: currentCursor,
40+
name: nameDebounce,
41+
}),
42+
// placeholderData: (previousData) => previousData,
3143
});
3244

3345
const handleNextPage = () => {
3446
if (teamList?.nextCursor) {
35-
console.log("yes cursor available")
47+
console.log("yes cursor available");
3648
setCursorHistory((prev) => [...prev, currentCursor ?? ""]); // Store current cursor
3749
setCurrentCursor(teamList.nextCursor); // Move to the next page
3850
}
@@ -51,33 +63,43 @@ export default function Teams() {
5163
// queryClient.invalidateQueries({queryKey: ["teams"]});
5264
// }
5365

54-
if (isLoading) {
55-
<>loading...</>;
56-
}
57-
if (isError) {
58-
<>skill issue</>;
59-
}
6066
const handleRowClick = (team: Team) => {
6167
setSelectedTeam(team);
6268
setOpen(true);
6369
};
6470

65-
6671
const handleModalClose = () => {
6772
setOpen(false);
6873
};
6974
return (
7075
<>
7176
<div className="p-4">
7277
<div className="mb-4"></div>
78+
<div className="mb-4 flex flex-col items-center">
79+
<input
80+
className="bg-gray w-[50%] rounded-md border p-2 text-white"
81+
placeholder="Enter Name..."
82+
value={theName}
83+
onChange={(e) => setTheName(e.target.value)}
84+
type="text"
85+
/>
86+
</div>
7387
{/* <DataTableUsers users={oosers} columns={userCol} /> */}
74-
{selectedTeam && <TeamModal open = {open} onClose = {handleModalClose} team = {selectedTeam}/>}
88+
{selectedTeam && (
89+
<TeamModal
90+
open={open}
91+
onClose={handleModalClose}
92+
team={selectedTeam}
93+
/>
94+
)}
7595
<DataTable<Team, string>
76-
columns={teamCol}
77-
data={teamList?.teams ?? []}
78-
handleNextPage={handleNextPage}
79-
handlePrevPage={handlePrevPage}
80-
onRowClick={handleRowClick}
96+
setPageLimit={setPageLimit}
97+
pageLimit={pageLimit}
98+
columns={teamCol}
99+
data={teamList?.teams ?? []}
100+
handleNextPage={handleNextPage}
101+
handlePrevPage={handlePrevPage}
102+
onRowClick={handleRowClick}
81103
/>
82104
</div>
83105
</>

src/app/todo/page.tsx

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)