import type { AdminViewServerProps, PayloadRequest } from 'payload' import { DefaultTemplate } from '@payloadcms/next/templates' import { Gutter } from '@payloadcms/ui' import type { ConsentCategory } from '../categories.js' import type { CookieScanLabels } from './labels.js' import { DocumentTitle } from '../../admin-i18n/DocumentTitle.js' import { adminDocumentTitle } from '../../admin-i18n/t.js' import { DEFAULT_UNKNOWN_CATEGORY, loadCookieApproval } from './approval.js' import { COOKIE_REVIEW_SLUG } from './collection.js' import { CookieApprovalForm } from './CookieApprovalForm.js' import { COOKIE_SCAN_LABELS, labelFor } from './labels.js' type Props = { adminRoute?: string labels?: Record unknownCategory?: ConsentCategory } & AdminViewServerProps /** Whether the user may read the review list — its own `access.read` decides (collectionOverrides narrow it). */ async function canReview(req: PayloadRequest): Promise { const read = req.payload.collections[COOKIE_REVIEW_SLUG as never]?.config.access?.read if (!read || !req.user) {return false} try { return Boolean(await read({ req } as never)) } catch { return false } } /** * Admin view at /admin/cookie-approval (`cookieScanner.approval`, on by * default): everything the latest scans found, grouped by consent category, * with one "Approve and add" button. Texts in the content locale that matches * the admin language, else the default locale. */ export async function CookieApprovalView(props: Props) { const { adminRoute = '/admin', initPageResult, labels = COOKIE_SCAN_LABELS, searchParams, unknownCategory = DEFAULT_UNKNOWN_CATEGORY } = props const { req, visibleEntities } = initPageResult const lang = req.i18n.language const t = (key: keyof CookieScanLabels) => labelFor(labels, lang, key) const l = req.payload.config.localization const locale = l ? (l.localeCodes.includes(lang) ? lang : l.defaultLocale) : 'en' const allowed = await canReview(req) const list = allowed ? await loadCookieApproval({ locale, payload: req.payload, req }) : null return (

{t('approvalTitle')}

{list ? ( ) : (

{t('approvalNoAccess')}

)}
) } export default CookieApprovalView