mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-01 09:13:57 +00:00
temporary fix for build and remove previous auth related code
This commit is contained in:
@ -8,8 +8,6 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { auth } from "@/app/auth";
|
||||
import prisma from "@/lib/db";
|
||||
import { headers } from "next/headers";
|
||||
import Link from "next/link";
|
||||
import BlockDeviceDialog from "../block-device-dialog";
|
||||
@ -27,178 +25,178 @@ export async function AdminDevicesTable({
|
||||
}>;
|
||||
parentalControl?: boolean;
|
||||
}) {
|
||||
const session = await auth.api.getSession({
|
||||
headers: await headers(),
|
||||
});
|
||||
const isAdmin = session?.user.role === "ADMIN";
|
||||
const query = (await searchParams)?.query || "";
|
||||
const page = (await searchParams)?.page;
|
||||
const sortBy = (await searchParams)?.sortBy || "asc";
|
||||
const totalDevices = await prisma.device.count({
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
name: {
|
||||
contains: query || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
{
|
||||
mac: {
|
||||
contains: query || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
// const session = await auth.api.getSession({
|
||||
// headers: await headers(),
|
||||
// });
|
||||
// const isAdmin = session?.user.role === "ADMIN";
|
||||
// const query = (await searchParams)?.query || "";
|
||||
// const page = (await searchParams)?.page;
|
||||
// const sortBy = (await searchParams)?.sortBy || "asc";
|
||||
// const totalDevices = await prisma.device.count({
|
||||
// where: {
|
||||
// OR: [
|
||||
// {
|
||||
// name: {
|
||||
// contains: query || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// mac: {
|
||||
// contains: query || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// });
|
||||
|
||||
const totalPages = Math.ceil(totalDevices / 10);
|
||||
const limit = 10;
|
||||
const offset = (Number(page) - 1) * limit || 0;
|
||||
// const totalPages = Math.ceil(totalDevices / 10);
|
||||
// const limit = 10;
|
||||
// const offset = (Number(page) - 1) * limit || 0;
|
||||
|
||||
const devices = await prisma.device.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
name: {
|
||||
contains: query || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
{
|
||||
mac: {
|
||||
contains: query || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
include: {
|
||||
User: true,
|
||||
payments: true,
|
||||
},
|
||||
skip: offset,
|
||||
take: limit,
|
||||
orderBy: {
|
||||
name: `${sortBy}` as "asc" | "desc",
|
||||
},
|
||||
});
|
||||
// const devices = await prisma.device.findMany({
|
||||
// where: {
|
||||
// OR: [
|
||||
// {
|
||||
// name: {
|
||||
// contains: query || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// mac: {
|
||||
// contains: query || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// include: {
|
||||
// User: true,
|
||||
// payments: true,
|
||||
// },
|
||||
// skip: offset,
|
||||
// take: limit,
|
||||
// orderBy: {
|
||||
// name: `${sortBy}` as "asc" | "desc",
|
||||
// },
|
||||
// });
|
||||
return null;
|
||||
// return (
|
||||
// <div>
|
||||
// {devices.length === 0 ? (
|
||||
// <div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
||||
// <h3>No devices yet.</h3>
|
||||
// </div>
|
||||
// ) : (
|
||||
// <>
|
||||
// <div className="hidden sm:block">
|
||||
// <Table className="overflow-scroll">
|
||||
// <TableCaption>Table of all devices.</TableCaption>
|
||||
// <TableHeader>
|
||||
// <TableRow>
|
||||
// <TableHead>Device Name</TableHead>
|
||||
// <TableHead>User</TableHead>
|
||||
// <TableHead>MAC Address</TableHead>
|
||||
// <TableHead>isActive</TableHead>
|
||||
// <TableHead>blocked</TableHead>
|
||||
// <TableHead>blockedBy</TableHead>
|
||||
// <TableHead>expiryDate</TableHead>
|
||||
// </TableRow>
|
||||
// </TableHeader>
|
||||
// <TableBody className="overflow-scroll">
|
||||
// {devices.map((device) => (
|
||||
// <TableRow key={device.id}>
|
||||
// <TableCell>
|
||||
// <div className="flex flex-col items-start">
|
||||
// <Link
|
||||
// className="font-medium hover:underline"
|
||||
// href={`/devices/${device.id}`}
|
||||
// >
|
||||
// {device.name}
|
||||
// </Link>
|
||||
// {device.isActive && (
|
||||
// <span className="text-muted-foreground">
|
||||
// Active until{" "}
|
||||
// {new Date().toLocaleDateString("en-US", {
|
||||
// month: "short",
|
||||
// day: "2-digit",
|
||||
// year: "numeric",
|
||||
// })}
|
||||
// </span>
|
||||
// )}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{devices.length === 0 ? (
|
||||
<div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
||||
<h3>No devices yet.</h3>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="hidden sm:block">
|
||||
<Table className="overflow-scroll">
|
||||
<TableCaption>Table of all devices.</TableCaption>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Device Name</TableHead>
|
||||
<TableHead>User</TableHead>
|
||||
<TableHead>MAC Address</TableHead>
|
||||
<TableHead>isActive</TableHead>
|
||||
<TableHead>blocked</TableHead>
|
||||
<TableHead>blockedBy</TableHead>
|
||||
<TableHead>expiryDate</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody className="overflow-scroll">
|
||||
{devices.map((device) => (
|
||||
<TableRow key={device.id}>
|
||||
<TableCell>
|
||||
<div className="flex flex-col items-start">
|
||||
<Link
|
||||
className="font-medium hover:underline"
|
||||
href={`/devices/${device.id}`}
|
||||
>
|
||||
{device.name}
|
||||
</Link>
|
||||
{device.isActive && (
|
||||
<span className="text-muted-foreground">
|
||||
Active until{" "}
|
||||
{new Date().toLocaleDateString("en-US", {
|
||||
month: "short",
|
||||
day: "2-digit",
|
||||
year: "numeric",
|
||||
})}
|
||||
</span>
|
||||
)}
|
||||
// {device.blocked && (
|
||||
// <div className="p-2 rounded border my-2">
|
||||
// <span>Comment: </span>
|
||||
// <p className="text-neutral-500">
|
||||
// blocked because he was watching youtube
|
||||
// </p>
|
||||
// </div>
|
||||
// )}
|
||||
// </div>
|
||||
// </TableCell>
|
||||
// <TableCell className="font-medium">
|
||||
// {device.User?.name}
|
||||
// </TableCell>
|
||||
|
||||
{device.blocked && (
|
||||
<div className="p-2 rounded border my-2">
|
||||
<span>Comment: </span>
|
||||
<p className="text-neutral-500">
|
||||
blocked because he was watching youtube
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="font-medium">
|
||||
{device.User?.name}
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="font-medium">{device.mac}</TableCell>
|
||||
<TableCell>
|
||||
{device.isActive ? "Active" : "Inactive"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{device.blocked ? "Blocked" : "Not Blocked"}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{device.blocked ? device.blockedBy : ""}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{new Date().toLocaleDateString("en-US", {
|
||||
month: "short",
|
||||
day: "2-digit",
|
||||
year: "numeric",
|
||||
})}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<BlockDeviceDialog
|
||||
admin={isAdmin}
|
||||
type={device.blocked ? "unblock" : "block"}
|
||||
device={device}
|
||||
/>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
<TableFooter>
|
||||
<TableRow>
|
||||
<TableCell colSpan={7}>
|
||||
{query.length > 0 && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Showing {devices.length} locations for "{query}
|
||||
"
|
||||
</p>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground">
|
||||
{totalDevices} devices
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</TableFooter>
|
||||
</Table>
|
||||
<Pagination totalPages={totalPages} currentPage={page} />
|
||||
</div>
|
||||
<div className="sm:hidden my-4">
|
||||
{devices.map((device) => (
|
||||
<DeviceCard
|
||||
parentalControl={parentalControl}
|
||||
key={device.id}
|
||||
device={device}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
// <TableCell className="font-medium">{device.mac}</TableCell>
|
||||
// <TableCell>
|
||||
// {device.isActive ? "Active" : "Inactive"}
|
||||
// </TableCell>
|
||||
// <TableCell>
|
||||
// {device.blocked ? "Blocked" : "Not Blocked"}
|
||||
// </TableCell>
|
||||
// <TableCell>
|
||||
// {device.blocked ? device.blockedBy : ""}
|
||||
// </TableCell>
|
||||
// <TableCell>
|
||||
// {new Date().toLocaleDateString("en-US", {
|
||||
// month: "short",
|
||||
// day: "2-digit",
|
||||
// year: "numeric",
|
||||
// })}
|
||||
// </TableCell>
|
||||
// <TableCell>
|
||||
// <BlockDeviceDialog
|
||||
// admin={isAdmin}
|
||||
// type={device.blocked ? "unblock" : "block"}
|
||||
// device={device}
|
||||
// />
|
||||
// </TableCell>
|
||||
// </TableRow>
|
||||
// ))}
|
||||
// </TableBody>
|
||||
// <TableFooter>
|
||||
// <TableRow>
|
||||
// <TableCell colSpan={7}>
|
||||
// {query.length > 0 && (
|
||||
// <p className="text-sm text-muted-foreground">
|
||||
// Showing {devices.length} locations for "{query}
|
||||
// "
|
||||
// </p>
|
||||
// )}
|
||||
// </TableCell>
|
||||
// <TableCell className="text-muted-foreground">
|
||||
// {totalDevices} devices
|
||||
// </TableCell>
|
||||
// </TableRow>
|
||||
// </TableFooter>
|
||||
// </Table>
|
||||
// <Pagination totalPages={totalPages} currentPage={page} />
|
||||
// </div>
|
||||
// <div className="sm:hidden my-4">
|
||||
// {devices.map((device) => (
|
||||
// <DeviceCard
|
||||
// parentalControl={parentalControl}
|
||||
// key={device.id}
|
||||
// device={device}
|
||||
// />
|
||||
// ))}
|
||||
// </div>
|
||||
// </>
|
||||
// )}
|
||||
// </div>
|
||||
// );
|
||||
}
|
||||
|
@ -2,228 +2,234 @@ 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,
|
||||
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,
|
||||
}: {
|
||||
searchParams: Promise<{
|
||||
query: string;
|
||||
page: number;
|
||||
sortBy: string;
|
||||
status: string;
|
||||
}>;
|
||||
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 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 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 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 (
|
||||
<div>
|
||||
{payments.length === 0 ? (
|
||||
<div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
||||
<h3>No user payments yet.</h3>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<Table className="overflow-scroll">
|
||||
<TableCaption>Table of all users.</TableCaption>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Devices paid</TableHead>
|
||||
<TableHead>User</TableHead>
|
||||
<TableHead>Amount</TableHead>
|
||||
<TableHead>Duration</TableHead>
|
||||
<TableHead>Payment Status</TableHead>
|
||||
<TableHead>Payment Method</TableHead>
|
||||
<TableHead>Paid At</TableHead>
|
||||
<TableHead>Action</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody className="overflow-scroll">
|
||||
{payments.map((payment) => (
|
||||
<TableRow
|
||||
className={`${payment.paid && "title-bg dark:bg-black"}`}
|
||||
key={payment.id}
|
||||
>
|
||||
<TableCell className="font-medium">
|
||||
<ol className="list-disc list-inside text-sm">
|
||||
{payment.devices.map((device) => (
|
||||
<li key={device.id} className="text-sm text-muted-foreground">
|
||||
{device.name}
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</TableCell>
|
||||
<TableCell className="font-medium">{payment.user.id_card}</TableCell>
|
||||
<TableCell>{payment.user?.name}</TableCell>
|
||||
<TableCell>{payment.user?.name}</TableCell>
|
||||
<TableCell>{payment.id}</TableCell>
|
||||
// const users = await prisma.user.findMany({
|
||||
// where: {
|
||||
// role: "USER",
|
||||
// },
|
||||
// include: {
|
||||
// atoll: true,
|
||||
// island: true,
|
||||
// },
|
||||
// });
|
||||
return null;
|
||||
// return (
|
||||
// <div>
|
||||
// {payments.length === 0 ? (
|
||||
// <div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
||||
// <h3>No user payments yet.</h3>
|
||||
// </div>
|
||||
// ) : (
|
||||
// <>
|
||||
// <Table className="overflow-scroll">
|
||||
// <TableCaption>Table of all users.</TableCaption>
|
||||
// <TableHeader>
|
||||
// <TableRow>
|
||||
// <TableHead>Devices paid</TableHead>
|
||||
// <TableHead>User</TableHead>
|
||||
// <TableHead>Amount</TableHead>
|
||||
// <TableHead>Duration</TableHead>
|
||||
// <TableHead>Payment Status</TableHead>
|
||||
// <TableHead>Payment Method</TableHead>
|
||||
// <TableHead>Paid At</TableHead>
|
||||
// <TableHead>Action</TableHead>
|
||||
// </TableRow>
|
||||
// </TableHeader>
|
||||
// <TableBody className="overflow-scroll">
|
||||
// {payments.map((payment) => (
|
||||
// <TableRow
|
||||
// className={`${payment.paid && "title-bg dark:bg-black"}`}
|
||||
// key={payment.id}
|
||||
// >
|
||||
// <TableCell className="font-medium">
|
||||
// <ol className="list-disc list-inside text-sm">
|
||||
// {payment.devices.map((device) => (
|
||||
// <li
|
||||
// key={device.id}
|
||||
// className="text-sm text-muted-foreground"
|
||||
// >
|
||||
// {device.name}
|
||||
// </li>
|
||||
// ))}
|
||||
// </ol>
|
||||
// </TableCell>
|
||||
// <TableCell className="font-medium">
|
||||
// {payment.user.id_card}
|
||||
// </TableCell>
|
||||
// <TableCell>{payment.user?.name}</TableCell>
|
||||
// <TableCell>{payment.user?.name}</TableCell>
|
||||
// <TableCell>{payment.id}</TableCell>
|
||||
|
||||
<TableCell>
|
||||
{payment.paid ? (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="bg-lime-100 text-black"
|
||||
>
|
||||
Verified
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="bg-yellow-100 text-black"
|
||||
>
|
||||
Unverified
|
||||
</Badge>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{new Date(payment.paidAt ?? "").toLocaleDateString("en-US", {
|
||||
month: "short",
|
||||
day: "2-digit",
|
||||
year: "numeric",
|
||||
})}
|
||||
</TableCell>
|
||||
// <TableCell>
|
||||
// {payment.paid ? (
|
||||
// <Badge
|
||||
// variant="outline"
|
||||
// className="bg-lime-100 text-black"
|
||||
// >
|
||||
// Verified
|
||||
// </Badge>
|
||||
// ) : (
|
||||
// <Badge
|
||||
// variant="outline"
|
||||
// className="bg-yellow-100 text-black"
|
||||
// >
|
||||
// Unverified
|
||||
// </Badge>
|
||||
// )}
|
||||
// </TableCell>
|
||||
// <TableCell>
|
||||
// {new Date(payment.paidAt ?? "").toLocaleDateString(
|
||||
// "en-US",
|
||||
// {
|
||||
// month: "short",
|
||||
// day: "2-digit",
|
||||
// year: "numeric",
|
||||
// },
|
||||
// )}
|
||||
// </TableCell>
|
||||
|
||||
<TableCell>{payment.id}</TableCell>
|
||||
<TableCell>
|
||||
<Link href={`/payments/${payment.id}/verify`}>
|
||||
<Button>
|
||||
Details
|
||||
</Button>
|
||||
</Link>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
<TableFooter>
|
||||
<TableRow>
|
||||
<TableCell colSpan={8}>
|
||||
{query.length > 0 && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Showing {payments.length} locations for "{query}
|
||||
"
|
||||
</p>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground">
|
||||
{totalPayments} payments
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</TableFooter>
|
||||
</Table>
|
||||
<Pagination totalPages={totalPages} currentPage={page} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
// <TableCell>{payment.id}</TableCell>
|
||||
// <TableCell>
|
||||
// <Link href={`/payments/${payment.id}/verify`}>
|
||||
// <Button>Details</Button>
|
||||
// </Link>
|
||||
// </TableCell>
|
||||
// </TableRow>
|
||||
// ))}
|
||||
// </TableBody>
|
||||
// <TableFooter>
|
||||
// <TableRow>
|
||||
// <TableCell colSpan={8}>
|
||||
// {query.length > 0 && (
|
||||
// <p className="text-sm text-muted-foreground">
|
||||
// Showing {payments.length} locations for "{query}
|
||||
// "
|
||||
// </p>
|
||||
// )}
|
||||
// </TableCell>
|
||||
// <TableCell className="text-muted-foreground">
|
||||
// {totalPayments} payments
|
||||
// </TableCell>
|
||||
// </TableRow>
|
||||
// </TableFooter>
|
||||
// </Table>
|
||||
// <Pagination totalPages={totalPages} currentPage={page} />
|
||||
// </>
|
||||
// )}
|
||||
// </div>
|
||||
// );
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import prisma from "@/lib/db";
|
||||
import Link from "next/link";
|
||||
import Pagination from "./pagination";
|
||||
import { Badge } from "./ui/badge";
|
||||
@ -28,84 +27,84 @@ export async function UsersTable({
|
||||
const page = (await searchParams)?.page;
|
||||
const sortBy = (await searchParams)?.sortBy || "asc";
|
||||
const verified = (await searchParams)?.status || "all";
|
||||
const totalUsers = await prisma.user.count({
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
name: {
|
||||
contains: query || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
{
|
||||
phoneNumber: {
|
||||
contains: query || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
{
|
||||
address: {
|
||||
contains: query || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
{
|
||||
id_card: {
|
||||
contains: query || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
],
|
||||
verified: verified === "all" ? undefined : verified === "verified",
|
||||
},
|
||||
// const totalUsers = await prisma.user.count({
|
||||
// where: {
|
||||
// OR: [
|
||||
// {
|
||||
// name: {
|
||||
// contains: query || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// phoneNumber: {
|
||||
// contains: query || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// address: {
|
||||
// contains: query || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// id_card: {
|
||||
// contains: query || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// verified: verified === "all" ? undefined : verified === "verified",
|
||||
// },
|
||||
|
||||
});
|
||||
// });
|
||||
|
||||
const totalPages = Math.ceil(totalUsers / 10);
|
||||
const limit = 10;
|
||||
const offset = (Number(page) - 1) * limit || 0;
|
||||
// const totalPages = Math.ceil(totalUsers / 10);
|
||||
// const limit = 10;
|
||||
// const offset = (Number(page) - 1) * limit || 0;
|
||||
|
||||
const users = await prisma.user.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
name: {
|
||||
contains: query || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
{
|
||||
phoneNumber: {
|
||||
contains: query || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
{
|
||||
address: {
|
||||
contains: query || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
{
|
||||
id_card: {
|
||||
contains: query || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
],
|
||||
verified: verified === "all" ? undefined : verified === "verified",
|
||||
// const users = await prisma.user.findMany({
|
||||
// where: {
|
||||
// OR: [
|
||||
// {
|
||||
// name: {
|
||||
// contains: query || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// phoneNumber: {
|
||||
// contains: query || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// address: {
|
||||
// contains: query || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// id_card: {
|
||||
// contains: query || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// verified: verified === "all" ? undefined : verified === "verified",
|
||||
|
||||
},
|
||||
include: {
|
||||
island: true,
|
||||
atoll: true,
|
||||
},
|
||||
skip: offset,
|
||||
take: limit,
|
||||
orderBy: {
|
||||
id: `${sortBy}` as "asc" | "desc",
|
||||
},
|
||||
});
|
||||
// },
|
||||
// include: {
|
||||
// island: true,
|
||||
// atoll: true,
|
||||
// },
|
||||
// skip: offset,
|
||||
// take: limit,
|
||||
// orderBy: {
|
||||
// id: `${sortBy}` as "asc" | "desc",
|
||||
// },
|
||||
// });
|
||||
|
||||
// const users = await prisma.user.findMany({
|
||||
// where: {
|
||||
@ -116,96 +115,95 @@ export async function UsersTable({
|
||||
// island: true,
|
||||
// },
|
||||
// });
|
||||
return (
|
||||
<div>
|
||||
{users.length === 0 ? (
|
||||
<div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
||||
<h3>No Users yet.</h3>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<Table className="overflow-scroll">
|
||||
<TableCaption>Table of all users.</TableCaption>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Name</TableHead>
|
||||
<TableHead>ID Card</TableHead>
|
||||
<TableHead>Atoll</TableHead>
|
||||
<TableHead>Island</TableHead>
|
||||
<TableHead>House Name</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead>Dob</TableHead>
|
||||
<TableHead>Phone Number</TableHead>
|
||||
<TableHead>Action</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody className="overflow-scroll">
|
||||
{users.map((user) => (
|
||||
<TableRow
|
||||
className={`${user.verified && "title-bg dark:bg-black"}`}
|
||||
key={user.id}
|
||||
>
|
||||
<TableCell className="font-medium">{user.name}</TableCell>
|
||||
<TableCell className="font-medium">{user.id_card}</TableCell>
|
||||
<TableCell>{user.atoll?.name}</TableCell>
|
||||
<TableCell>{user.island?.name}</TableCell>
|
||||
<TableCell>{user.address}</TableCell>
|
||||
return null;
|
||||
// return (
|
||||
// <div>
|
||||
// {users.length === 0 ? (
|
||||
// <div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
||||
// <h3>No Users yet.</h3>
|
||||
// </div>
|
||||
// ) : (
|
||||
// <>
|
||||
// <Table className="overflow-scroll">
|
||||
// <TableCaption>Table of all users.</TableCaption>
|
||||
// <TableHeader>
|
||||
// <TableRow>
|
||||
// <TableHead>Name</TableHead>
|
||||
// <TableHead>ID Card</TableHead>
|
||||
// <TableHead>Atoll</TableHead>
|
||||
// <TableHead>Island</TableHead>
|
||||
// <TableHead>House Name</TableHead>
|
||||
// <TableHead>Status</TableHead>
|
||||
// <TableHead>Dob</TableHead>
|
||||
// <TableHead>Phone Number</TableHead>
|
||||
// <TableHead>Action</TableHead>
|
||||
// </TableRow>
|
||||
// </TableHeader>
|
||||
// <TableBody className="overflow-scroll">
|
||||
// {users.map((user) => (
|
||||
// <TableRow
|
||||
// className={`${user.verified && "title-bg dark:bg-black"}`}
|
||||
// key={user.id}
|
||||
// >
|
||||
// <TableCell className="font-medium">{user.name}</TableCell>
|
||||
// <TableCell className="font-medium">{user.id_card}</TableCell>
|
||||
// <TableCell>{user.atoll?.name}</TableCell>
|
||||
// <TableCell>{user.island?.name}</TableCell>
|
||||
// <TableCell>{user.address}</TableCell>
|
||||
|
||||
<TableCell>
|
||||
{user.verified ? (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="bg-lime-100 text-black"
|
||||
>
|
||||
Verified
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="bg-yellow-100 text-black"
|
||||
>
|
||||
Unverified
|
||||
</Badge>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{new Date(user.dob ?? "").toLocaleDateString("en-US", {
|
||||
month: "short",
|
||||
day: "2-digit",
|
||||
year: "numeric",
|
||||
})}
|
||||
</TableCell>
|
||||
// <TableCell>
|
||||
// {user.verified ? (
|
||||
// <Badge
|
||||
// variant="outline"
|
||||
// className="bg-lime-100 text-black"
|
||||
// >
|
||||
// Verified
|
||||
// </Badge>
|
||||
// ) : (
|
||||
// <Badge
|
||||
// variant="outline"
|
||||
// className="bg-yellow-100 text-black"
|
||||
// >
|
||||
// Unverified
|
||||
// </Badge>
|
||||
// )}
|
||||
// </TableCell>
|
||||
// <TableCell>
|
||||
// {new Date(user.dob ?? "").toLocaleDateString("en-US", {
|
||||
// month: "short",
|
||||
// day: "2-digit",
|
||||
// year: "numeric",
|
||||
// })}
|
||||
// </TableCell>
|
||||
|
||||
<TableCell>{user.phoneNumber}</TableCell>
|
||||
<TableCell>
|
||||
<Link href={`/users/${user.id}/verify`}>
|
||||
<Button>
|
||||
Details
|
||||
</Button>
|
||||
</Link>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
<TableFooter>
|
||||
<TableRow>
|
||||
<TableCell colSpan={8}>
|
||||
{query.length > 0 && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Showing {users.length} locations for "{query}
|
||||
"
|
||||
</p>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground">
|
||||
{totalUsers} users
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</TableFooter>
|
||||
</Table>
|
||||
<Pagination totalPages={totalPages} currentPage={page} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
// <TableCell>{user.phoneNumber}</TableCell>
|
||||
// <TableCell>
|
||||
// <Link href={`/users/${user.id}/verify`}>
|
||||
// <Button>Details</Button>
|
||||
// </Link>
|
||||
// </TableCell>
|
||||
// </TableRow>
|
||||
// ))}
|
||||
// </TableBody>
|
||||
// <TableFooter>
|
||||
// <TableRow>
|
||||
// <TableCell colSpan={8}>
|
||||
// {query.length > 0 && (
|
||||
// <p className="text-sm text-muted-foreground">
|
||||
// Showing {users.length} locations for "{query}
|
||||
// "
|
||||
// </p>
|
||||
// )}
|
||||
// </TableCell>
|
||||
// <TableCell className="text-muted-foreground">
|
||||
// {totalUsers} users
|
||||
// </TableCell>
|
||||
// </TableRow>
|
||||
// </TableFooter>
|
||||
// </Table>
|
||||
// <Pagination totalPages={totalPages} currentPage={page} />
|
||||
// </>
|
||||
// )}
|
||||
// </div>
|
||||
// );
|
||||
}
|
||||
|
Reference in New Issue
Block a user