refactor: add tryCatch utility for error handling, update device-related components and types, and clean up unused code in payment actions
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 13m55s

This commit is contained in:
2025-04-05 16:07:11 +05:00
parent dbdc1df7d5
commit aa18484475
16 changed files with 641 additions and 599 deletions

View File

@ -8,25 +8,15 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
import prisma from "@/lib/db";
import Link from "next/link";
import { auth } from "@/app/auth";
import { cn } from "@/lib/utils";
import type { Prisma } from "@prisma/client";
import { Calendar } from "lucide-react";
import { headers } from "next/headers";
import Pagination from "./pagination";
import { Badge } from "./ui/badge";
import { Button } from "./ui/button";
import { Separator } from "./ui/separator";
type PaymentWithDevices = Prisma.PaymentGetPayload<{
include: {
devices: true;
};
}>;
export async function PaymentsTable({
searchParams,
}: {
@ -36,60 +26,61 @@ export async function PaymentsTable({
sortBy: string;
}>;
}) {
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 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 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,
},
// 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",
},
});
// skip: offset,
// take: limit,
// orderBy: {
// createdAt: "desc",
// },
// });
return null;
return (
<div>
{payments.length === 0 ? (