Skip to content

Commit b408041

Browse files
authored
Add admin courses table view (#35)
1 parent 2b6ce16 commit b408041

File tree

2 files changed

+188
-3
lines changed

2 files changed

+188
-3
lines changed

src/app/admin/courses/page.tsx

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,72 @@
1-
export default function Page() {
2-
return (<div>This is the admin course page!</div>);
3-
}
1+
import {
2+
Table,
3+
TableBody,
4+
TableCell,
5+
TableHead,
6+
TableHeader,
7+
TableRow,
8+
} from "@/components/ui/table";
9+
10+
// dummy course array
11+
const dummyCourses = [
12+
{
13+
id: "1",
14+
title: "Intro to Python",
15+
description: "Learn Python for beginners",
16+
status: "published",
17+
},
18+
{
19+
id: "2",
20+
title: "Web Development Basics",
21+
description: "Web dev fundamentals",
22+
status: "published",
23+
},
24+
{
25+
id: "3",
26+
title: "Data Structures",
27+
description: "Learn about core data structures",
28+
status: "unpublished",
29+
},
30+
{
31+
id: "4",
32+
title: "Advanced JavaScript",
33+
description: "Advanced topics in JavaScript",
34+
status: "published",
35+
},
36+
{
37+
id: "5",
38+
title: "React Fundamentals",
39+
description: "Build modern web apps with React",
40+
status: "unpublished",
41+
},
42+
];
43+
44+
// admin course page setup
45+
export default function AdminCoursesPage() {
46+
return (
47+
<div className="container mx-auto py-10">
48+
<h1 className="text-3xl font-bold mb-8">Admin Data Table</h1>
49+
50+
<div className="rounded-md border">
51+
<Table>
52+
<TableHeader>
53+
<TableRow>
54+
<TableHead>Title</TableHead>
55+
<TableHead>Description</TableHead>
56+
<TableHead>Status</TableHead>
57+
</TableRow>
58+
</TableHeader>
59+
<TableBody>
60+
{dummyCourses.map((course) => (
61+
<TableRow key={course.id}>
62+
<TableCell>{course.title}</TableCell>
63+
<TableCell>{course.description}</TableCell>
64+
<TableCell>{course.status}</TableCell>
65+
</TableRow>
66+
))}
67+
</TableBody>
68+
</Table>
69+
</div>
70+
</div>
71+
);
72+
}

src/components/ui/table.tsx

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
"use client"
2+
3+
import * as React from "react"
4+
5+
import { cn } from "@/lib/utils"
6+
7+
function Table({ className, ...props }: React.ComponentProps<"table">) {
8+
return (
9+
<div
10+
data-slot="table-container"
11+
className="relative w-full overflow-x-auto"
12+
>
13+
<table
14+
data-slot="table"
15+
className={cn("w-full caption-bottom text-sm", className)}
16+
{...props}
17+
/>
18+
</div>
19+
)
20+
}
21+
22+
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
23+
return (
24+
<thead
25+
data-slot="table-header"
26+
className={cn("[&_tr]:border-b", className)}
27+
{...props}
28+
/>
29+
)
30+
}
31+
32+
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
33+
return (
34+
<tbody
35+
data-slot="table-body"
36+
className={cn("[&_tr:last-child]:border-0", className)}
37+
{...props}
38+
/>
39+
)
40+
}
41+
42+
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
43+
return (
44+
<tfoot
45+
data-slot="table-footer"
46+
className={cn(
47+
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
48+
className
49+
)}
50+
{...props}
51+
/>
52+
)
53+
}
54+
55+
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
56+
return (
57+
<tr
58+
data-slot="table-row"
59+
className={cn(
60+
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
61+
className
62+
)}
63+
{...props}
64+
/>
65+
)
66+
}
67+
68+
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
69+
return (
70+
<th
71+
data-slot="table-head"
72+
className={cn(
73+
"text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
74+
className
75+
)}
76+
{...props}
77+
/>
78+
)
79+
}
80+
81+
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
82+
return (
83+
<td
84+
data-slot="table-cell"
85+
className={cn(
86+
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
87+
className
88+
)}
89+
{...props}
90+
/>
91+
)
92+
}
93+
94+
function TableCaption({
95+
className,
96+
...props
97+
}: React.ComponentProps<"caption">) {
98+
return (
99+
<caption
100+
data-slot="table-caption"
101+
className={cn("text-muted-foreground mt-4 text-sm", className)}
102+
{...props}
103+
/>
104+
)
105+
}
106+
107+
export {
108+
Table,
109+
TableHeader,
110+
TableBody,
111+
TableFooter,
112+
TableHead,
113+
TableRow,
114+
TableCell,
115+
TableCaption,
116+
}

0 commit comments

Comments
 (0)