mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-15 04:55:49 +00:00
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
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 5m25s
This commit is contained in:
@ -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 offset = (page - 1) * limit;
|
||||||
|
const apiParams: Record<string, string | number | undefined> = {};
|
||||||
|
for (const [key, value] of Object.entries(resolvedParams)) {
|
||||||
|
if (value !== undefined && value !== "") {
|
||||||
|
apiParams[key] = typeof value === "number" ? value : String(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// const totalPages = Math.ceil(totalUsers / 10);
|
apiParams.limit = limit;
|
||||||
// const limit = 10;
|
apiParams.offset = offset;
|
||||||
// const offset = (Number(page) - 1) * limit || 0;
|
const [error, users] = await tryCatch(getUsers(apiParams));
|
||||||
|
if (error) {
|
||||||
|
if (error.message === "UNAUTHORIZED") {
|
||||||
|
redirect("/auth/signin");
|
||||||
|
}
|
||||||
|
return <ClientErrorMessage message={error.message} />;
|
||||||
|
}
|
||||||
|
const { meta, data } = users;
|
||||||
|
|
||||||
// const users = await prisma.user.findMany({
|
// return null;
|
||||||
// where: {
|
return (
|
||||||
// OR: [
|
<div>
|
||||||
// {
|
{users?.data.length === 0 ? (
|
||||||
// name: {
|
<div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
||||||
// contains: query || "",
|
<h3>No Users yet.</h3>
|
||||||
// mode: "insensitive",
|
</div>
|
||||||
// },
|
) : (
|
||||||
// },
|
<>
|
||||||
// {
|
<Table className="overflow-scroll">
|
||||||
// phoneNumber: {
|
<TableCaption>Table of all users.</TableCaption>
|
||||||
// contains: query || "",
|
<TableHeader>
|
||||||
// mode: "insensitive",
|
<TableRow>
|
||||||
// },
|
<TableHead>Name</TableHead>
|
||||||
// },
|
<TableHead>ID Card</TableHead>
|
||||||
// {
|
<TableHead>Atoll</TableHead>
|
||||||
// address: {
|
<TableHead>Island</TableHead>
|
||||||
// contains: query || "",
|
<TableHead>House Name</TableHead>
|
||||||
// mode: "insensitive",
|
<TableHead>Status</TableHead>
|
||||||
// },
|
<TableHead>Dob</TableHead>
|
||||||
// },
|
<TableHead>Phone Number</TableHead>
|
||||||
// {
|
<TableHead>Action</TableHead>
|
||||||
// id_card: {
|
</TableRow>
|
||||||
// contains: query || "",
|
</TableHeader>
|
||||||
// mode: "insensitive",
|
<TableBody className="overflow-scroll">
|
||||||
// },
|
{data.map((user) => (
|
||||||
// },
|
<TableRow
|
||||||
// ],
|
className={`${user.verified && "title-bg dark:bg-black"}`}
|
||||||
// verified: verified === "all" ? undefined : verified === "verified",
|
key={user.id}
|
||||||
|
>
|
||||||
|
<TableCell className="font-medium">{user.first_name} {user.last_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>
|
||||||
// include: {
|
{user.verified ? (
|
||||||
// island: true,
|
<Badge
|
||||||
// atoll: true,
|
variant="outline"
|
||||||
// },
|
className="bg-lime-100 text-black"
|
||||||
// skip: offset,
|
>
|
||||||
// take: limit,
|
Verified
|
||||||
// orderBy: {
|
</Badge>
|
||||||
// id: `${sortBy}` as "asc" | "desc",
|
) : (
|
||||||
// },
|
<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>
|
||||||
|
|
||||||
// const users = await prisma.user.findMany({
|
<TableCell>{user.mobile}</TableCell>
|
||||||
// where: {
|
<TableCell>
|
||||||
// role: "USER",
|
<Link href={`/users/${user.id}/verify`}>
|
||||||
// },
|
<Button>Details</Button>
|
||||||
// include: {
|
</Link>
|
||||||
// atoll: true,
|
</TableCell>
|
||||||
// island: true,
|
</TableRow>
|
||||||
// },
|
))}
|
||||||
// });
|
</TableBody>
|
||||||
return null;
|
<TableFooter>
|
||||||
// return (
|
<TableRow>
|
||||||
// <div>
|
<TableCell colSpan={9}>
|
||||||
// {users.length === 0 ? (
|
{meta?.total === 1 ? (
|
||||||
// <div className="h-[calc(100svh-400px)] flex flex-col items-center justify-center my-4">
|
<p className="text-center">Total {meta?.total} user.</p>
|
||||||
// <h3>No Users yet.</h3>
|
) : (
|
||||||
// </div>
|
<p className="text-center">Total {meta?.total} users.</p>
|
||||||
// ) : (
|
)}
|
||||||
// <>
|
</TableCell>
|
||||||
// <Table className="overflow-scroll">
|
</TableRow>
|
||||||
// <TableCaption>Table of all users.</TableCaption>
|
</TableFooter>
|
||||||
// <TableHeader>
|
</Table>
|
||||||
// <TableRow>
|
<Pagination totalPages={meta?.last_page}
|
||||||
// <TableHead>Name</TableHead>
|
currentPage={meta?.current_page} />
|
||||||
// <TableHead>ID Card</TableHead>
|
</>
|
||||||
// <TableHead>Atoll</TableHead>
|
)}
|
||||||
// <TableHead>Island</TableHead>
|
</div>
|
||||||
// <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.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>
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
|
@ -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",
|
||||||
|
Reference in New Issue
Block a user