Rooms queried the wrong Prisma model and a non-existent owner relation. Settings now use grouped managed fields plus a searchable advanced key/value panel. Co-authored-by: Cursor <[email protected]>
71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
import { fetchAdminList } from "@/lib/admin-list";
|
|
import { canAccess, PERMS } from "@/lib/permissions";
|
|
import { RoomsTable } from "./rooms-table";
|
|
|
|
export default async function RoomsPage({
|
|
params: paramsPromise,
|
|
searchParams,
|
|
}: {
|
|
params: Promise<{ locale?: string }>;
|
|
searchParams: Promise<Record<string, string>>;
|
|
}) {
|
|
const result = await fetchAdminList(
|
|
{
|
|
permission: PERMS.ROOMS_VIEW,
|
|
// Prisma model is `Rooms` → client accessor `rooms`.
|
|
// Owner is denormalized on the row (ownerId / ownerName), not a relation.
|
|
model: "rooms",
|
|
searchFields: ["name", "ownerName"],
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
ownerId: true,
|
|
ownerName: true,
|
|
state: true,
|
|
users: true,
|
|
usersMax: true,
|
|
description: true,
|
|
},
|
|
filterMap: {
|
|
filter_state: (v) => ({ state: v }),
|
|
},
|
|
mapRow: (r) => ({
|
|
id: r.id as number,
|
|
name: r.name as string,
|
|
ownerName: (r.ownerName as string) || "—",
|
|
ownerId: (r.ownerId as number) ?? 0,
|
|
state: r.state as string,
|
|
users: r.users as number,
|
|
usersMax: r.usersMax as number,
|
|
description: (r.description as string) || "",
|
|
}),
|
|
},
|
|
paramsPromise as Promise<{ locale: string }>,
|
|
searchParams,
|
|
);
|
|
|
|
const canEdit = canAccess(result.permissions, PERMS.ROOMS_EDIT, result.rank);
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<div>
|
|
<h1 className="text-3xl font-bold tracking-tight">Rooms</h1>
|
|
<p className="text-muted-foreground">
|
|
{result.total.toLocaleString()} rooms total
|
|
</p>
|
|
</div>
|
|
|
|
<RoomsTable
|
|
data={{
|
|
rows: result.rows,
|
|
total: result.total,
|
|
page: result.page,
|
|
perPage: result.perPage,
|
|
lastPage: result.lastPage,
|
|
}}
|
|
canEdit={canEdit}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|