Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

110 user table table pagination not functioning #150

Merged
merged 9 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@radix-ui/react-switch": "^1.0.3",
"@react-email/components": "^0.0.21",
"@t3-oss/env-nextjs": "^0.10.1",
"@tanstack/match-sorter-utils": "^8.19.4",
"@tanstack/react-query": "^5.51.11",
"@tanstack/react-table": "^8.19.3",
"@trpc/client": "11.0.0-rc.466",
Expand Down
50 changes: 8 additions & 42 deletions apps/web/src/app/admin/users/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,16 @@ import { DataTable } from "@/components/admin/users/UserDataTable";
import { columns } from "@/components/admin/users/UserColumns";
import { Button } from "@/components/shadcn/ui/button";
import { FolderInput } from "lucide-react";
import { DefaultPagination } from "@/components/admin/users/DefaultPagination";
import SearchBar from "@/components/admin/users/SearchBar";
import { getAllUsers } from "db/functions";
import { userCommonData } from "db/schema";

export default async function Page({
searchParams,
}: {
searchParams: { [key: string]: string | undefined };
}) {
// COME BACK AND CHANGE
const maxPerPage = 30;

let page = +(searchParams["page"] ?? "1");
let user = searchParams["user"] ?? "";
const checkedBoxes = searchParams["checkedBoxes"] ?? "";

console.log(checkedBoxes);

const start = maxPerPage * (page - 1);
const end = maxPerPage + start;

// Might want to work with cache in prod to see if this will be plausible to do
const userData = await db.query.userCommonData.findMany({
with: { hackerData: true },
where: and(
or(
ilike(userCommonData.firstName, `%${user}%`),
ilike(userCommonData.lastName, `%${user}%`),
),
),
});
// This begs a question where we might want to have an option later on to sort by the role as we might want different things
export default async function Page() {
const userData = await getAllUsers();

return (
<div className="mx-auto max-w-7xl px-5 pt-44">
<div className="mb-5 grid w-full grid-cols-3">
<div className="mx-auto max-w-7xl px-5 pt-40">
<div className="mb-5 grid w-full grid-cols-2">
<div className="flex items-center">
<div>
<h2 className="text-3xl font-bold tracking-tight">
Expand All @@ -48,7 +23,6 @@ export default async function Page({
</p>
</div>
</div>
<SearchBar />
<div className="flex items-center justify-end">
<a download href="/api/admin/export">
<Button className="flex gap-x-1">
Expand All @@ -58,25 +32,17 @@ export default async function Page({
</a>
</div>
</div>
{/* TODO: Would very much like to not have "as any" here in the future */}
<div className="flex w-full space-x-10">
<div className="flex w-full justify-center">
{userData && userData.length > 0 ? (
<>
<DataTable
columns={columns}
data={userData.slice(start, end) as any}
/>
<DataTable columns={columns} data={userData} />
</>
) : (
<div className="flex w-full items-center justify-center">
<h1>No Results :(</h1>
</div>
)}
{/* <Filters/> */}
</div>
<DefaultPagination
maxPages={Math.ceil(userData.length / maxPerPage)}
/>
</div>
);
}
Expand Down
73 changes: 0 additions & 73 deletions apps/web/src/components/admin/users/DefaultPagination.tsx

This file was deleted.

45 changes: 0 additions & 45 deletions apps/web/src/components/admin/users/SearchBar.tsx

This file was deleted.

Loading
Loading