From 549a9737db7faa93556142f8a82c7a2f97c8e172 Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Fri, 3 Jan 2025 16:20:26 -0700 Subject: [PATCH] feat(next): pass through query params from document view to find operations --- packages/next/src/views/Account/index.tsx | 1 + .../next/src/views/CreateFirstUser/index.tsx | 1 + .../src/views/Document/getDocumentData.ts | 21 ++++++++++++++++++- packages/next/src/views/Document/index.tsx | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/next/src/views/Account/index.tsx b/packages/next/src/views/Account/index.tsx index 5ebb71523b4..06f27899e7e 100644 --- a/packages/next/src/views/Account/index.tsx +++ b/packages/next/src/views/Account/index.tsx @@ -51,6 +51,7 @@ export const Account: React.FC = async ({ collectionSlug: collectionConfig.slug, locale, payload, + req, user, }) diff --git a/packages/next/src/views/CreateFirstUser/index.tsx b/packages/next/src/views/CreateFirstUser/index.tsx index 1c3ad788d58..4edbec045a0 100644 --- a/packages/next/src/views/CreateFirstUser/index.tsx +++ b/packages/next/src/views/CreateFirstUser/index.tsx @@ -34,6 +34,7 @@ export const CreateFirstUserView: React.FC = async ({ initPageRe collectionSlug: collectionConfig.slug, locale, payload: req.payload, + req, user: req.user, }) diff --git a/packages/next/src/views/Document/getDocumentData.ts b/packages/next/src/views/Document/getDocumentData.ts index 4b9a86abc07..f1ca4226ca7 100644 --- a/packages/next/src/views/Document/getDocumentData.ts +++ b/packages/next/src/views/Document/getDocumentData.ts @@ -1,5 +1,12 @@ import { sanitizeID } from '@payloadcms/ui/shared' -import { type Locale, logError, type Payload, type TypedUser, type TypeWithID } from 'payload' +import { + type Locale, + logError, + type Payload, + type PayloadRequest, + type TypedUser, + type TypeWithID, +} from 'payload' type Args = { collectionSlug?: string @@ -7,6 +14,7 @@ type Args = { id?: number | string locale?: Locale payload: Payload + req?: PayloadRequest user?: TypedUser } @@ -16,6 +24,7 @@ export const getDocumentData = async ({ globalSlug, locale, payload, + req, user, }: Args): Promise | TypeWithID> => { const id = sanitizeID(idArg) @@ -31,6 +40,11 @@ export const getDocumentData = async ({ fallbackLocale: false, locale: locale?.code, overrideAccess: false, + req: { + query: req?.query, + search: req?.search, + searchParams: req?.searchParams, + }, user, }) } @@ -43,6 +57,11 @@ export const getDocumentData = async ({ fallbackLocale: false, locale: locale?.code, overrideAccess: false, + req: { + query: req?.query, + search: req?.search, + searchParams: req?.searchParams, + }, user, }) } diff --git a/packages/next/src/views/Document/index.tsx b/packages/next/src/views/Document/index.tsx index c882328d972..ea66635815a 100644 --- a/packages/next/src/views/Document/index.tsx +++ b/packages/next/src/views/Document/index.tsx @@ -87,6 +87,7 @@ export const renderDocument = async ({ globalSlug, locale, payload, + req, user, }))