import { authOptions } from "@/app/auth"; import { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { getDevices } from "@/queries/devices"; import { tryCatch } from "@/utils/tryCatch"; import { getServerSession } from "next-auth"; import { redirect } from "next/navigation"; import ClickableRow from "./clickable-row"; import ClientErrorMessage from "./client-error-message"; import DeviceCard from "./device-card"; import Pagination from "./pagination"; export async function DevicesTable({ searchParams, parentalControl, }: { searchParams: Promise<{ query: string; page: number; }>; parentalControl?: boolean; }) { const session = await getServerSession(authOptions); const isAdmin = session?.user?.is_superuser; const query = (await searchParams)?.query || ""; const page = (await searchParams)?.page || 1; const limit = 10; // Items per page const offset = (page - 1) * limit; // Calculate offset based on page const [error, devices] = await tryCatch( getDevices({ query: query, limit: limit, offset: offset }), ); if (error) { if (error.message === "UNAUTHORIZED") { redirect("/auth/signin"); } else { return ; } } const { meta, data } = devices; return (
{data?.length === 0 ? (

No devices yet.

) : ( <>
Table of all devices. Device Name MAC Address # {data?.map((device) => ( ))} {query?.length > 0 && (

Showing {meta?.total} devices for "{query} "

)}
{meta?.total} devices
{data?.map((device) => ( ))}
)}
); }