import { authOptions } from "@/app/auth"; import { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { getServerSession } from "next-auth"; import ClickableRow from "./clickable-row"; import DeviceCard from "./device-card"; import Pagination from "./pagination"; export async function DevicesTable({ searchParams, parentalControl, }: { searchParams: Promise<{ query: string; page: number; sortBy: string; }>; parentalControl?: boolean; }) { const session = await getServerSession(authOptions); const isAdmin = session?.user; const query = (await searchParams)?.query || ""; const page = (await searchParams)?.page; const sortBy = (await searchParams)?.sortBy || "asc"; // const totalDevices = await prisma.device.count({ // where: { // userId: isAdmin ? undefined : session?.session.userId, // OR: [ // { // name: { // contains: query || "", // mode: "insensitive", // }, // }, // { // mac: { // contains: query || "", // mode: "insensitive", // }, // }, // ], // NOT: { // payments: { // some: { // paid: false, // }, // }, // }, // isActive: isAdmin ? undefined : parentalControl, // blocked: isAdmin // ? undefined // : parentalControl !== undefined // ? undefined // : false, // }, // }); // const totalPages = Math.ceil(totalDevices / 10); const limit = 10; const offset = (Number(page) - 1) * limit || 0; // const devices = await prisma.device.findMany({ // where: { // userId: session?.session.userId, // OR: [ // { // name: { // contains: query || "", // mode: "insensitive", // }, // }, // { // mac: { // contains: query || "", // mode: "insensitive", // }, // }, // ], // NOT: { // payments: { // some: { // paid: false, // }, // }, // }, // isActive: parentalControl, // blocked: parentalControl !== undefined ? undefined : false, // }, // skip: offset, // take: limit, // orderBy: { // name: `${sortBy}` as "asc" | "desc", // }, // }); return null; return (
{devices.length === 0 ? (

No devices yet.

) : ( <>
Table of all devices. Device Name MAC Address # {devices.map((device) => ( // // //
// // {device.name} // // // Active until{" "} // {new Date().toLocaleDateString("en-US", { // month: "short", // day: "2-digit", // year: "numeric", // })} // // {parentalControl && ( //
// Comment: //

// blocked because he was watching youtube //

//
// )} //
//
// {device.mac} // // {!parentalControl ? ( // // ) : ( // // )} // //
))}
{query.length > 0 && (

Showing {devices.length} locations for "{query} "

)}
{totalDevices} devices
{devices.map((device) => ( ))}
)}
); }