Skip to content

Commit 02fc65e

Browse files
Merge pull request #8 from CodeChefVIT/harshit/users
real time fetching
2 parents 0122ee1 + d81f337 commit 02fc65e

9 files changed

Lines changed: 152 additions & 89 deletions

File tree

src/api/fetchTeams.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { type Team } from "@/data/schema"
2+
import {type TeamsResponse} from "@/data/schema"
23
import axios from "./axiosConfig";
34

45

56
export const fetchTeams = async()=>{
67
try{
7-
const response = await axios.get('admin/teams')
8-
console.log(response.data)
9-
return response.data as Team[];
8+
const response = await axios.get<TeamsResponse>('admin/teams?limit=10')
9+
console.log(response.data.data.teams)
10+
return response.data.data.teams;
1011
}catch(err){
1112
throw err;
1213
}

src/api/fetchUsers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { type User } from "@/data/schema"
2+
import {type UserResponse} from "@/data/schema"
23
import axios from "./axiosConfig";
34

45

56
export const fetchUsers = async()=>{
67
try{
7-
const response = await axios.get('admin/users')
8+
const response = await axios.get<UserResponse>('admin/users?limit=10')
89
console.log(response.data)
9-
return response.data as User[];
10+
return response.data.data.users;
1011
}catch(err){
12+
console.log(err)
1113
throw err;
1214
}
1315
}

src/app/teams/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function Teams() {
3131
<div className="p-4">
3232
<div className="mb-4"></div>
3333
{/* <DataTableUsers users={oosers} columns={userCol} /> */}
34-
<DataTable<Team, string> columns={teamCol} data={tooms} />
34+
<DataTable<Team, string> columns={teamCol} data={teamList ?? []} />
3535
</div>
3636
</>
3737
);

src/app/users/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ export default function Users() {
8282
<div className="p-4">
8383
<div className="mb-4"></div>
8484
{/* <DataTableUsers users={oosers} columns={userCol} /> */}
85-
<DataTable<User, string> columns={userCol} data={oosers} />
85+
<DataTable<User, string> columns={userCol} data={userList ?? []} />
86+
8687
</div>
8788
);
8889
}

src/components/columns/TeamCol.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,36 @@ const columns: ColumnDef<Team>[] = [
3232
enableHiding: false,
3333
},
3434
{
35-
accessorKey: "id",
35+
accessorKey: "ID",
3636
header: ({ column }) => <DataTableColumnHeader column={column} title="Team ID" />,
37-
cell: ({ row }) => <div className="w-[80px]">{row.getValue("id")}</div>,
37+
cell: ({ row }) => <div className="w-[80px]">{row.getValue("ID")}</div>,
3838
},
3939
{
40-
accessorKey: "name",
40+
accessorKey: "Name",
4141
header: ({ column }) => <DataTableColumnHeader column={column} title="Team Name" />,
42-
cell: ({ row }) => <span>{row.getValue("name")}</span>,
42+
cell: ({ row }) => <span>{row.getValue("Name")}</span>,
4343
},
4444
{
45-
accessorKey: "number_of_people",
45+
accessorKey: "NumberOfPeople",
4646
header: ({ column }) => <DataTableColumnHeader column={column} title="Number of People" />,
47-
cell: ({ row }) => <span>{row.getValue("number_of_people")}</span>,
47+
cell: ({ row }) => <span>{row.getValue("NumberOfPeople")}</span>,
4848
},
4949
{
50-
accessorKey: "round_qualified",
50+
accessorKey: "RoundQualified",
5151
header: ({ column }) => <DataTableColumnHeader column={column} title="Round Qualified" />,
52-
cell: ({ row }) => <span>{row.getValue("round_qualified")}</span>,
52+
cell: ({ row }) => <span>{row.getValue("RoundQualified")}</span>,
5353
},
5454
{
55-
accessorKey: "code",
55+
accessorKey: "Code",
5656
header: ({ column }) => <DataTableColumnHeader column={column} title="Team Code" />,
57-
cell: ({ row }) => <span>{row.getValue("code")}</span>,
57+
cell: ({ row }) => <span>{row.getValue("Code")}</span>,
58+
},
59+
{
60+
accessorKey: "IsBanned",
61+
header: ({ column }) => <DataTableColumnHeader column={column} title="Banned" />,
62+
cell: ({ row }) => (
63+
<span>{row.getValue("IsBanned") ? "Yes" : "No"}</span>
64+
),
5865
},
5966
{
6067
id: "actions",

src/components/columns/UserCol.tsx

Lines changed: 72 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { Checkbox } from "@/components/ui/checkbox";
55
import { DataTableColumnHeader } from "@/components/table/data-table-column-header";
66
import { Badge } from "@/components/ui/badge";
77
import { DataTableRowActions } from "@/components/table/data-table-row-actions";
8-
import { type User } from "@/data/schema"
9-
8+
import { type User } from "@/data/schema";
109

1110
const columns: ColumnDef<User>[] = [
1211
{
@@ -34,80 +33,104 @@ const columns: ColumnDef<User>[] = [
3433
enableHiding: false,
3534
},
3635
{
37-
accessorKey: "id",
36+
accessorKey: "ID",
3837
header: ({ column }) => <DataTableColumnHeader column={column} title="ID" />,
39-
cell: ({ row }) => <div className="w-[80px]">{row.getValue("id")}</div>,
38+
cell: ({ row }) => <div className="w-[80px]">{row.getValue("ID")}</div>,
39+
},
40+
{
41+
accessorKey: "FirstName",
42+
header: ({ column }) => <DataTableColumnHeader column={column} title="First Name" />,
43+
cell: ({ row }) => <span>{row.getValue("FirstName")}</span>,
4044
},
4145
{
42-
accessorKey: "name",
43-
header: ({ column }) => <DataTableColumnHeader column={column} title="Name" />,
44-
cell: ({ row }) => <span>{row.getValue("name")}</span>,
46+
accessorKey: "LastName",
47+
header: ({ column }) => <DataTableColumnHeader column={column} title="Last Name" />,
48+
cell: ({ row }) => <span>{row.getValue("LastName")}</span>,
4549
},
4650
{
47-
accessorKey: "email",
51+
accessorKey: "Email",
4852
header: ({ column }) => <DataTableColumnHeader column={column} title="Email" />,
49-
cell: ({ row }) => <span>{row.getValue("email")}</span>,
53+
cell: ({ row }) => <span>{row.getValue("Email")}</span>,
5054
},
5155
{
52-
accessorKey: "team_id",
56+
accessorKey: "TeamID",
5357
header: ({ column }) => <DataTableColumnHeader column={column} title="Team ID" />,
54-
cell: ({ row }) => <span>{row.getValue("team_id")}</span>,
58+
cell: ({ row }) => <span>{row.getValue("TeamID")}</span>,
5559
},
5660
{
57-
accessorKey: "is_vitian",
58-
header: ({ column }) => <DataTableColumnHeader column={column} title="VITian" />,
59-
cell: ({ row }) => (
60-
<Badge variant={row.getValue("is_vitian") ? "default" : "outline"}>
61-
{row.getValue("is_vitian") ? "Yes" : "No"}
62-
</Badge>
63-
),
61+
accessorKey: "Gender",
62+
header: ({ column }) => <DataTableColumnHeader column={column} title="Gender" />,
63+
cell: ({ row }) => <span>{row.getValue("Gender")}</span>,
6464
},
6565
{
66-
accessorKey: "reg_no",
66+
accessorKey: "RegNo",
6767
header: ({ column }) => <DataTableColumnHeader column={column} title="Reg No." />,
68-
cell: ({ row }) => <span>{row.getValue("reg_no")}</span>,
68+
cell: ({ row }) => <span>{row.getValue("RegNo")}</span>,
6969
},
7070
{
71-
accessorKey: "phone_no",
71+
accessorKey: "PhoneNo",
7272
header: ({ column }) => <DataTableColumnHeader column={column} title="Phone No." />,
73-
cell: ({ row }) => <span>{row.getValue("phone_no")}</span>,
73+
cell: ({ row }) => <span>{row.getValue("PhoneNo")}</span>,
7474
},
7575
{
76-
accessorKey: "role",
76+
accessorKey: "Role",
7777
header: ({ column }) => <DataTableColumnHeader column={column} title="Role" />,
78-
cell: ({ row }) => <span>{row.getValue("role")}</span>,
78+
cell: ({ row }) => <span>{row.getValue("Role")}</span>,
7979
},
80+
// {
81+
// accessorKey: "IsLeader",
82+
// header: ({ column }) => <DataTableColumnHeader column={column} title="Leader" />,
83+
// cell: ({ row }) => (
84+
// <Badge variant={row.getValue("IsLeader") ? "default" : "outline"}>
85+
// {row.getValue("IsLeader") ? "Yes" : "No"}
86+
// </Badge>
87+
// ),
88+
// // },
89+
// {
90+
// accessorKey: "IsVerified",
91+
// header: ({ column }) => <DataTableColumnHeader column={column} title="Verified" />,
92+
// cell: ({ row }) => (
93+
// <Badge variant={row.getValue("IsVerified") ? "default" : "outline"}>
94+
// {row.getValue("IsVerified") ? "Yes" : "No"}
95+
// </Badge>
96+
// ),
97+
// },
8098
{
81-
accessorKey: "is_leader",
82-
header: ({ column }) => <DataTableColumnHeader column={column} title="Leader" />,
99+
accessorKey: "IsBanned",
100+
header: ({ column }) => <DataTableColumnHeader column={column} title="Banned" />,
83101
cell: ({ row }) => (
84-
<Badge variant={row.getValue("is_leader") ? "default" : "outline"}>
85-
{row.getValue("is_leader") ? "Yes" : "No"}
102+
<Badge variant={row.getValue("IsBanned") ? "destructive" : "outline"}>
103+
{row.getValue("IsBanned") ? "Yes" : "No"}
86104
</Badge>
87105
),
88106
},
107+
// {
108+
// accessorKey: "IsProfileComplete",
109+
// header: ({ column }) => <DataTableColumnHeader column={column} title="Profile Complete" />,
110+
// cell: ({ row }) => (
111+
// <Badge variant={row.getValue("IsProfileComplete") ? "default" : "outline"}>
112+
// {row.getValue("IsProfileComplete") ? "Yes" : "No"}
113+
// </Badge>
114+
// ),
115+
// },
116+
// {
117+
// accessorKey: "IsStarred",
118+
// header: ({ column }) => <DataTableColumnHeader column={column} title="Starred" />,
119+
// cell: ({ row }) => (
120+
// <Badge variant={row.getValue("IsStarred") ? "default" : "outline"}>
121+
// {row.getValue("IsStarred") ? "Yes" : "No"}
122+
// </Badge>
123+
// ),
124+
// },
125+
// {
126+
// accessorKey: "RoomNo",
127+
// header: ({ column }) => <DataTableColumnHeader column={column} title="Room No." />,
128+
// cell: ({ row }) => <span>{row.getValue("RoomNo")}</span>,
129+
// },
89130
{
90-
accessorKey: "college",
91-
header: ({ column }) => <DataTableColumnHeader column={column} title="College" />,
92-
cell: ({ row }) => <span>{row.getValue("college")}</span>,
93-
},
94-
// {
95-
// accessorKey: "is_verified",
96-
// header: ({ column }) => <DataTableColumnHeader column={column} title="Verified" />,
97-
// cell: ({ row }) => (
98-
// <Badge variant={row.getValue("is_verified") ? "default" : "outline"}>
99-
// {row.getValue("is_verified") ? "Yes" : "No"}
100-
// </Badge>
101-
// ),
102-
// },
103-
{
104-
accessorKey: "is_banned",
105-
header: ({ column }) => <DataTableColumnHeader column={column} title="Banned" />,
106-
cell: ({ row }) => (
107-
<Badge variant={row.getValue("is_banned") ? "destructive" : "outline"}>
108-
{row.getValue("is_banned") ? "Yes" : "No"}
109-
</Badge>
110-
),
131+
accessorKey: "HostelBlock",
132+
header: ({ column }) => <DataTableColumnHeader column={column} title="Hostel Block" />,
133+
cell: ({ row }) => <span>{row.getValue("HostelBlock")}</span>,
111134
},
112135
{
113136
id: "actions",

src/components/table/data-table-row-actions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
DropdownMenuTrigger,
1919
} from "../ui/dropdown-menu"
2020
import { labels } from "@/data/data"
21-
import { taskSchema, userScheme } from "@/data/schema"
21+
import { taskSchema } from "@/data/schema"
2222

2323

2424
interface DataTableRowActionsProps<TData> {

src/components/table/data-table-toolbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export function DataTableToolbar<TData>({
2323
<div className="flex flex-1 items-center space-x-2">
2424
<Input
2525
placeholder="Filter..."
26-
value={(table.getColumn("name")?.getFilterValue() as string) ?? ""}
26+
value={(table.getColumn("Name")?.getFilterValue() as string) ?? ""}
2727
onChange={(event) =>
28-
table.getColumn("name")?.setFilterValue(event.target.value)
28+
table.getColumn("Name")?.setFilterValue(event.target.value)
2929
}
3030
className="h-8 w-[150px] lg:w-[250px]"
3131
/>

src/data/schema.ts

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,62 @@ export const taskSchema = z.object({
99
label: z.string(),
1010
priority: z.string(),
1111
})
12-
export const userScheme = z.object({
13-
id: z.number(),
14-
name: z.string(),
15-
email: z.string(),
16-
team_id: z.number().nullable(),
17-
is_vitian: z.boolean(),
18-
reg_no: z.string(),
19-
password: z.string(),
20-
phone_no: z.string(),
21-
role: z.string(),
22-
is_leader: z.boolean(),
23-
college: z.string(),
24-
is_verified: z.boolean(),
25-
is_banned: z.boolean(),
12+
const userSchema = z.object({
13+
ID: z.string(),
14+
TeamID: z.string().nullable(),
15+
FirstName: z.string(),
16+
LastName: z.string(),
17+
Email: z.string().email(),
18+
PhoneNo: z.string().nullable(),
19+
Gender: z.string(),
20+
RegNo: z.string().nullable(),
21+
GithubProfile: z.string().nullable(),
22+
Password: z.string(),
23+
Role: z.enum(["admin", "student"]),
24+
IsLeader: z.boolean(),
25+
IsVerified: z.boolean(),
26+
IsBanned: z.boolean(),
27+
IsProfileComplete: z.boolean(),
28+
IsStarred: z.boolean(),
29+
RoomNo: z.string().nullable(),
30+
HostelBlock: z.string().nullable(),
2631
});
2732

33+
// Response schema
34+
const usersResponseSchema = z.object({
35+
status: z.string(),
36+
message: z.string(),
37+
data: z.object({
38+
message: z.string(),
39+
users: z.array(userSchema),
40+
}),
41+
});
42+
43+
44+
2845

2946

3047
export const teamSchema = z.object({
31-
id: z.number(),
32-
name: z.string(),
33-
number_of_people: z.number(),
34-
round_qualified: z.number(),
35-
code: z.string(),
48+
ID: z.string(),
49+
Name: z.string(),
50+
NumberOfPeople: z.number(),
51+
RoundQualified: z.number(),
52+
Code: z.string(),
53+
IsBanned: z.boolean(),
54+
});
55+
56+
const TeamsResponseSchema = z.object({
57+
status: z.string(),
58+
message: z.string().optional(),
59+
data: z.object({
60+
message: z.string(),
61+
teams: z.array(teamSchema),
62+
}),
3663
});
3764

3865

3966
export type Task = z.infer<typeof taskSchema>
4067
export type Team = z.infer<typeof teamSchema>
41-
export type User = z.infer<typeof userScheme>;
68+
export type User = z.infer<typeof userSchema>;
69+
export type TeamsResponse = z.infer<typeof TeamsResponseSchema>;
70+
export type UserResponse = z.infer<typeof usersResponseSchema>;

0 commit comments

Comments
 (0)