"use client" import Button from "@components/button" import ButtonDropdown from "@components/button-dropdown" import { Spinner } from "@components/spinner" import { useToasts } from "@components/toasts" import { Post, User } from "@lib/server/prisma" import Link from "next/link" import { useState } from "react" import styles from "./table.module.css" export function UserTable({ users: initialUsers }: { users?: { createdAt: string posts?: Post[] id: string email: string | null role: string | null displayName: string | null }[] }) { const { setToast } = useToasts() const [users, setUsers] = useState(initialUsers) const deleteUser = async (id: string) => { try { const res = await fetch("/api/admin?action=delete-user", { method: "DELETE", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ userId: id }) }) if (res.status === 200) { setToast({ message: "User deleted", type: "success" }) setUsers(users?.filter((user) => user.id !== id)) } } catch (err) { console.error(err) setToast({ message: "Error deleting user", type: "error" }) } } return ( {!users ? ( ) : null} {users?.map((user) => ( ))}
Name Email Role User ID Actions
{user.displayName ? user.displayName : "no name"} {user.email} {user.role} {user.id}
) } export function PostTable({ posts }: { posts?: { createdAt: string id: string author?: User | null title: string visibility: string }[] }) { return ( {!posts ? ( ) : null} {posts?.map((post) => ( ))}
Title Author Created Visibility Post ID
{post.title} {"author" in post ? post.author?.name : "no author"} {new Date(post.createdAt).toLocaleDateString()} {post.visibility} {post.id}
) }