- {book.publication && ( - - Published: - - - )} -
-+ {book.publication && ( + + Published: + + + )} +
{book.summary}
@@ -139,7 +151,8 @@ export default function BookByIdPageClient(props: Props) { currentRepository={repos[0]} repositories={repos} isRequesting={isRequestingCopy} - isDisabled={isRequestDisabled} + doesHoldExist={doesHoldExist} + isDisabled={isRequestDisabled || !user} onClickRequest={onClickRequest} onChange={(repo) => setSelectedRepository(repo)} /> diff --git a/src/app/(frontend)/books/[bookId]/page.tsx b/src/app/(frontend)/books/[bookId]/page.tsx index 795cc44..627ab79 100644 --- a/src/app/(frontend)/books/[bookId]/page.tsx +++ b/src/app/(frontend)/books/[bookId]/page.tsx @@ -1,6 +1,7 @@ -import { Book, Copy, Repository } from '@/payload-types' +import { Book, Copy, HoldRequest, Repository } from '@/payload-types' import { getPayload, PaginatedDocs } from 'payload' import configPromise from '@payload-config' +import { headers as getHeaders } from 'next/headers.js' import BookByIdPageClient from './page.client' import { PageBreadCrumb, Route } from '@/components/PageBreadCrumb' @@ -31,7 +32,8 @@ const BookByIdPage = async (props: Props) => { const payload = await getPayload({ config: configPromise }) - const defaultRepositoryLimit = 10 + const headers = await getHeaders() + const { user } = await payload.auth({ headers }) const foundBook = (await payload.findByID({ collection: 'books', @@ -51,16 +53,45 @@ const BookByIdPage = async (props: Props) => { }, })) as Book - const repositoryIds = foundBook.copies?.docs?.map((c) => (c as Copy).repository) - - const orQueries = repositoryIds?.map((c) => { - return { - id: { - equals: c, + let existingHolds: PaginatedDocs