Skip to content

Commit fb7fcd2

Browse files
committed
Team Card Added
1 parent 27a3bd5 commit fb7fcd2

3 files changed

Lines changed: 96 additions & 2 deletions

File tree

src/app/teams/page.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ import teamCol from "@/components/columns/TeamCol";
66
// import { user } from "@/store/interfaces";
77
import tooms from "@/components/dumTeams.json";
88
// import useToast from "@/lib/toast";
9-
import { useQuery } from "@tanstack/react-query";
9+
import { useQuery, useQueryClient } from "@tanstack/react-query";
1010
import { type Team } from "@/data/schema";
1111
import { fetchTeams } from "@/api/fetchTeams";
1212
import { useState } from "react";
13+
import { TeamModal } from "@/components/table/team-modal";
1314

1415
export default function Teams() {
1516
const [pageIndex, setPageIndex] = useState(0);
1617
const [pageSize, setPageSize] = useState(10);
18+
const [selectedTeam, setSelectedTeam] = useState<Team | null>(null);
19+
const [open, setOpen] = useState(false);
20+
21+
const queryClient = useQueryClient();
1722

1823
const {
1924
data: teamList,
@@ -24,17 +29,37 @@ export default function Teams() {
2429
queryFn: () => fetchTeams({ page: pageIndex + 1, limit: pageSize }),
2530
});
2631

32+
const handlePageChange = (page: number)=>{
33+
setPageIndex(page);
34+
queryClient.invalidateQueries({queryKey: ["teams"]});
35+
}
36+
37+
const handlePageSizeChange = (size: number)=>{
38+
setPageSize(size);
39+
queryClient.invalidateQueries({queryKey: ["teams"]});
40+
}
41+
2742
if (isLoading) {
2843
<>loading...</>;
2944
}
3045
if (isError) {
3146
<>skill issue</>;
3247
}
48+
const handleRowClick = (team: Team) => {
49+
setSelectedTeam(team);
50+
setOpen(true);
51+
};
52+
53+
54+
const handleModalClose = () => {
55+
setOpen(false);
56+
};
3357
return (
3458
<>
3559
<div className="p-4">
3660
<div className="mb-4"></div>
3761
{/* <DataTableUsers users={oosers} columns={userCol} /> */}
62+
{selectedTeam && <TeamModal open = {open} onClose = {handleModalClose} team = {selectedTeam}/>}
3863
<DataTable<Team, string>
3964
columns={teamCol}
4065
data={teamList?.teams ?? []}
@@ -43,6 +68,7 @@ export default function Teams() {
4368
onPageSizeChange={setPageSize}
4469
currentPage = {pageIndex}
4570
pageSize = {pageSize}
71+
onRowClick={handleRowClick}
4672
/>
4773
</div>
4874
</>

src/components/table/data-table.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ interface DataTableProps<TData, TValue> {
3030
onPageSizeChange: (size: number) => void
3131
currentPage: number;
3232
pageSize: number;
33+
onRowClick?: (row: TData) => void;
3334
}
3435

3536
export function DataTable<TData, TValue>({
@@ -39,7 +40,8 @@ export function DataTable<TData, TValue>({
3940
onPageChange,
4041
onPageSizeChange,
4142
currentPage,
42-
pageSize
43+
pageSize,
44+
onRowClick,
4345
}: DataTableProps<TData, TValue>) {
4446
const [rowSelection, setRowSelection] = React.useState({});
4547
const [columnVisibility, setColumnVisibility] =
@@ -116,6 +118,11 @@ export function DataTable<TData, TValue>({
116118
<TableRow
117119
key={row.id}
118120
data-state={row.getIsSelected() && "selected"}
121+
onClick={() => {
122+
if (onRowClick) {
123+
onRowClick(row.original);
124+
}
125+
}}
119126
>
120127
{row.getVisibleCells().map((cell) => (
121128
<TableCell key={cell.id}>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import {
2+
Dialog,
3+
DialogContent,
4+
DialogDescription,
5+
DialogHeader,
6+
DialogTitle,
7+
DialogTrigger,
8+
DialogClose
9+
} from "@/components/ui/dialog";
10+
import { type Team } from "@/data/schema";
11+
import { Button } from "../ui/button";
12+
13+
interface TeamModalProps{
14+
open: boolean;
15+
onClose: () => void;
16+
team: Team;
17+
}
18+
export const TeamModal = ({open, onClose, team}: TeamModalProps) => {
19+
return (<Dialog open={open} onOpenChange={onClose}>
20+
<DialogContent className="sm:max-w-[425px]">
21+
<DialogHeader>
22+
<DialogTitle>Team Details</DialogTitle>
23+
<DialogDescription>
24+
Here are details about the selected Team
25+
</DialogDescription>
26+
</DialogHeader>
27+
<div className="grid gap-4 py-4">
28+
<div className="grid grid-cols-4 gap-2">
29+
<div className="text-gray-100">ID</div>
30+
<div className="col-span-3 text-gray-100 font-medium">{team.ID}</div>
31+
</div>
32+
<div className="grid grid-cols-4 gap-2">
33+
<div className="text-gray-100">Name</div>
34+
<div className="col-span-3 text-gray-100 font-medium">{team.Name}</div>
35+
</div>
36+
<div className="grid grid-cols-4 gap-2">
37+
<div className="text-gray-100">Members</div>
38+
<div className="col-span-3 text-gray-100 font-medium">{team.NumberOfPeople}</div>
39+
</div>
40+
<div className="grid grid-cols-4 gap-2">
41+
<div className="text-gray-100">Code</div>
42+
<div className="col-span-3 text-gray-100 font-medium">{team.Code}</div>
43+
</div>
44+
<div className="grid grid-cols-4 gap-2">
45+
<div className="text-gray-100">Round</div>
46+
<div className="col-span-3 text-gray-100 font-medium">{team.RoundQualified}</div>
47+
</div>
48+
<div className="grid grid-cols-4 gap-2">
49+
<div className="text-gray-100">Banned</div>
50+
<div className="col-span-3 text-gray-100 font-medium">{team.IsBanned ? 'Yes': 'No'}</div>
51+
</div>
52+
</div>
53+
<div className="flex justify-end">
54+
<DialogClose asChild>
55+
<Button>Close</Button>
56+
</DialogClose>
57+
</div>
58+
</DialogContent>
59+
</Dialog>
60+
)
61+
}

0 commit comments

Comments
 (0)