import { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import Link from "next/link"; import { getPayments } from "@/actions/payment"; import type { Payment } from "@/lib/backend-types"; import { cn } from "@/lib/utils"; import { tryCatch } from "@/utils/tryCatch"; import { Calendar } from "lucide-react"; import { redirect } from "next/navigation"; import Pagination from "./pagination"; import { Badge } from "./ui/badge"; import { Button } from "./ui/button"; import { Separator } from "./ui/separator"; export async function PaymentsTable({ searchParams, }: { searchParams: Promise<{ query: string; page: number; sortBy: string; }>; }) { const query = (await searchParams)?.query || ""; // const session = await auth.api.getSession({ // headers: await headers(), // }); // const query = (await searchParams)?.query || ""; // const page = (await searchParams)?.page; // const totalPayments = await prisma.payment.count({ // where: { // userId: session?.session.userId, // OR: [ // { // devices: { // every: { // name: { // contains: query || "", // mode: "insensitive", // }, // }, // }, // }, // ], // }, // }); // const totalPages = Math.ceil(totalPayments / 10); // const limit = 10; // const offset = (Number(page) - 1) * limit || 0; // const payments = await prisma.payment.findMany({ // where: { // userId: session?.session.userId, // OR: [ // { // devices: { // every: { // name: { // contains: query || "", // mode: "insensitive", // }, // }, // }, // }, // ], // }, // include: { // devices: true, // }, // skip: offset, // take: limit, // orderBy: { // createdAt: "desc", // }, // }); const [error, payments] = await tryCatch(getPayments()); if (error) { if (error.message.includes("Unauthorized")) { redirect("/auth/signin"); } else { return
{JSON.stringify(error, null, 2)}; } } const { data, meta, links } = payments; return (