feat(admin): add usertable and update next config
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 5m25s

This commit is contained in:
2025-07-13 23:09:02 +05:00
parent d198a1bdcf
commit 780239dbbe
2 changed files with 130 additions and 197 deletions

View File

@ -13,198 +13,141 @@
// import { Badge } from "./ui/badge"; // import { Badge } from "./ui/badge";
// import { Button } from "./ui/button"; // import { Button } from "./ui/button";
import Link from "next/link";
import { redirect } from "next/navigation";
import { getUsers } from "@/queries/users";
import { tryCatch } from "@/utils/tryCatch";
import ClientErrorMessage from "./client-error-message";
import Pagination from "./pagination";
import { Badge } from "./ui/badge";
import { Button } from "./ui/button";
import {
Table,
TableBody,
TableCaption,
TableCell,
TableFooter,
TableHead,
TableHeader,
TableRow,
} from "./ui/table";
export async function UsersTable({ export async function UsersTable({
searchParams, searchParams,
}: { }: {
searchParams: Promise<{ searchParams: Promise<{
query: string; [key: string]: unknown;
page: number;
sortBy: string;
status: string;
}>; }>;
}) { }) {
const query = (await searchParams)?.query || ""; const resolvedParams = await searchParams;
console.log(query);
// 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 page = Number.parseInt(resolvedParams.page as string) || 1;
const limit = 10;
// const totalPages = Math.ceil(totalUsers / 10); const offset = (page - 1) * limit;
// const limit = 10; const apiParams: Record<string, string | number | undefined> = {};
// const offset = (Number(page) - 1) * limit || 0; for (const [key, value] of Object.entries(resolvedParams)) {
if (value !== undefined && value !== "") {
// const users = await prisma.user.findMany({ apiParams[key] = typeof value === "number" ? value : String(value);
// where: { }
// OR: [ }
// {
// name: { apiParams.limit = limit;
// contains: query || "", apiParams.offset = offset;
// mode: "insensitive", const [error, users] = await tryCatch(getUsers(apiParams));
// }, if (error) {
// }, if (error.message === "UNAUTHORIZED") {
// { redirect("/auth/signin");
// phoneNumber: { }
// contains: query || "", return <ClientErrorMessage message={error.message} />;
// mode: "insensitive", }
// }, const { meta, data } = users;
// },
// { // return null;
// address: { return (
// contains: query || "", <div>
// mode: "insensitive", {users?.data.length === 0 ? (
// }, <div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
// }, <h3>No Users yet.</h3>
// { </div>
// id_card: { ) : (
// contains: query || "", <>
// mode: "insensitive", <Table className="overflow-scroll">
// }, <TableCaption>Table of all users.</TableCaption>
// }, <TableHeader>
// ], <TableRow>
// verified: verified === "all" ? undefined : verified === "verified", <TableHead>Name</TableHead>
<TableHead>ID Card</TableHead>
// }, <TableHead>Atoll</TableHead>
// include: { <TableHead>Island</TableHead>
// island: true, <TableHead>House Name</TableHead>
// atoll: true, <TableHead>Status</TableHead>
// }, <TableHead>Dob</TableHead>
// skip: offset, <TableHead>Phone Number</TableHead>
// take: limit, <TableHead>Action</TableHead>
// orderBy: { </TableRow>
// id: `${sortBy}` as "asc" | "desc", </TableHeader>
// }, <TableBody className="overflow-scroll">
// }); {data.map((user) => (
<TableRow
// const users = await prisma.user.findMany({ className={`${user.verified && "title-bg dark:bg-black"}`}
// where: { key={user.id}
// role: "USER", >
// }, <TableCell className="font-medium">{user.first_name} {user.last_name}</TableCell>
// include: { <TableCell className="font-medium">{user.id_card}</TableCell>
// atoll: true, <TableCell>{user.atoll?.name}</TableCell>
// island: true, <TableCell>{user.island?.name}</TableCell>
// }, <TableCell>{user.address}</TableCell>
// });
return null; <TableCell>
// return ( {user.verified ? (
// <div> <Badge
// {users.length === 0 ? ( variant="outline"
// <div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4"> className="bg-lime-100 text-black"
// <h3>No Users yet.</h3> >
// </div> Verified
// ) : ( </Badge>
// <> ) : (
// <Table className="overflow-scroll"> <Badge
// <TableCaption>Table of all users.</TableCaption> variant="outline"
// <TableHeader> className="bg-yellow-100 text-black"
// <TableRow> >
// <TableHead>Name</TableHead> Unverified
// <TableHead>ID Card</TableHead> </Badge>
// <TableHead>Atoll</TableHead> )}
// <TableHead>Island</TableHead> </TableCell>
// <TableHead>House Name</TableHead> <TableCell>
// <TableHead>Status</TableHead> {new Date(user.dob ?? "").toLocaleDateString("en-US", {
// <TableHead>Dob</TableHead> month: "short",
// <TableHead>Phone Number</TableHead> day: "2-digit",
// <TableHead>Action</TableHead> year: "numeric",
// </TableRow> })}
// </TableHeader> </TableCell>
// <TableBody className="overflow-scroll">
// {users.map((user) => ( <TableCell>{user.mobile}</TableCell>
// <TableRow <TableCell>
// className={`${user.verified && "title-bg dark:bg-black"}`} <Link href={`/users/${user.id}/verify`}>
// key={user.id} <Button>Details</Button>
// > </Link>
// <TableCell className="font-medium">{user.name}</TableCell> </TableCell>
// <TableCell className="font-medium">{user.id_card}</TableCell> </TableRow>
// <TableCell>{user.atoll?.name}</TableCell> ))}
// <TableCell>{user.island?.name}</TableCell> </TableBody>
// <TableCell>{user.address}</TableCell> <TableFooter>
<TableRow>
// <TableCell> <TableCell colSpan={9}>
// {user.verified ? ( {meta?.total === 1 ? (
// <Badge <p className="text-center">Total {meta?.total} user.</p>
// variant="outline" ) : (
// className="bg-lime-100 text-black" <p className="text-center">Total {meta?.total} users.</p>
// > )}
// Verified </TableCell>
// </Badge> </TableRow>
// ) : ( </TableFooter>
// <Badge </Table>
// variant="outline" <Pagination totalPages={meta?.last_page}
// className="bg-yellow-100 text-black" currentPage={meta?.current_page} />
// > </>
// Unverified )}
// </Badge> </div>
// )} );
// </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 &quot;{query}
// &quot;
// </p>
// )}
// </TableCell>
// <TableCell className="text-muted-foreground">
// {totalUsers} users
// </TableCell>
// </TableRow>
// </TableFooter>
// </Table>
// <Pagination totalPages={totalPages} currentPage={page} />
// </>
// )}
// </div>
// );
} }

View File

@ -4,20 +4,10 @@ const nextConfig: NextConfig = {
/* config options here */ /* config options here */
images: { images: {
remotePatterns: [ remotePatterns: [
{ new URL('http://people-api.sarlink.net/images/**'),
protocol: "http", new URL('http://verifypersonapi.baraveli.dev/images/**'),
hostname: "verifypersonapi.baraveli.dev", new URL('https://i.pravatar.cc/300/**'),
pathname: "/images/**", new URL('https://sarlink-portal.vercel.app/**'),
search: "",
port: "",
},
{
protocol: "https",
hostname: "i.pravatar.cc",
pathname: "/300/**",
search: "",
port: "",
},
], ],
}, },
output: "standalone", output: "standalone",