import Pagination from "@/components/pagination"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import prisma from "@/lib/db"; import Link from "next/link"; export async function UsersPaymentsTable({ searchParams, }: { searchParams: Promise<{ query: string; page: number; sortBy: string; status: string; }>; }) { const query = (await searchParams)?.query || ""; const page = (await searchParams)?.page; const sortBy = (await searchParams)?.sortBy || "asc"; const totalPayments = await prisma.payment.count({ where: { OR: [ { user: { name: { contains: query || "", mode: "insensitive", } }, }, { user: { phoneNumber: { contains: query || "", mode: "insensitive", } }, }, { user: { address: { contains: query || "", mode: "insensitive", } }, }, { user: { id_card: { 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: { OR: [ { user: { name: { contains: query || "", mode: "insensitive", } }, }, { user: { phoneNumber: { contains: query || "", mode: "insensitive", } }, }, { user: { address: { contains: query || "", mode: "insensitive", } }, }, { user: { id_card: { contains: query || "", mode: "insensitive", } }, }, ], }, include: { user: true, devices: true, }, skip: offset, take: limit, orderBy: { id: `${sortBy}` as "asc" | "desc", }, }); // const users = await prisma.user.findMany({ // where: { // role: "USER", // }, // include: { // atoll: true, // island: true, // }, // }); return (
{payments.length === 0 ? (

No Users yet.

) : ( <> Table of all users. Devices paid User Amount Duration Payment Status Payment Method Paid At Action {payments.map((payment) => (
    {payment.devices.map((device) => (
  1. {device.name}
  2. ))}
{payment.user.id_card} {payment.user?.name} {payment.user?.name} {payment.id} {payment.paid ? ( Verified ) : ( Unverified )} {new Date(payment.paidAt ?? "").toLocaleDateString("en-US", { month: "short", day: "2-digit", year: "numeric", })} {payment.id}
))}
{query.length > 0 && (

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

)}
{totalPayments} payments
)}
); }