2022-11-14 04:28:40 -05:00
|
|
|
import { getAllPosts, getAllUsers } from "@lib/server/prisma"
|
|
|
|
import { getCurrentUser } from "@lib/server/session"
|
|
|
|
import { notFound } from "next/navigation"
|
2022-04-09 20:48:19 -04:00
|
|
|
import styles from "./admin.module.css"
|
2022-04-13 00:14:10 -04:00
|
|
|
import PostTable from "./post-table"
|
|
|
|
import UserTable from "./user-table"
|
2022-03-29 03:11:02 -04:00
|
|
|
|
2022-11-14 04:28:40 -05:00
|
|
|
const Admin = async () => {
|
|
|
|
const user = await getCurrentUser()
|
|
|
|
if (!user) {
|
|
|
|
return notFound()
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user.role !== "admin") {
|
|
|
|
return notFound()
|
2022-04-13 00:14:10 -04:00
|
|
|
}
|
2022-03-28 15:13:22 -04:00
|
|
|
|
2022-11-14 04:28:40 -05:00
|
|
|
const posts = await getAllPosts()
|
|
|
|
const users = await getAllUsers()
|
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
return (
|
|
|
|
<div className={styles.adminWrapper}>
|
2022-11-08 03:23:28 -05:00
|
|
|
<h2>Administration</h2>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
alignItems: "center",
|
|
|
|
gap: 4
|
|
|
|
}}
|
|
|
|
>
|
2022-11-14 04:28:40 -05:00
|
|
|
<UserTable users={users} />
|
|
|
|
<PostTable posts={posts} />
|
2022-11-08 03:23:28 -05:00
|
|
|
</div>
|
2022-04-09 20:48:19 -04:00
|
|
|
</div>
|
|
|
|
)
|
2022-03-28 15:13:22 -04:00
|
|
|
}
|
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
export default Admin
|