diff --git a/packages/next/src/utilities/initPage/handleAdminPage.ts b/packages/next/src/utilities/initPage/handleAdminPage.ts index 45e31beec8c..77c1da15a28 100644 --- a/packages/next/src/utilities/initPage/handleAdminPage.ts +++ b/packages/next/src/utilities/initPage/handleAdminPage.ts @@ -5,12 +5,15 @@ import type { SanitizedGlobalConfig, } from 'payload' +import { fieldAffectsData } from 'payload/shared' + import { getRouteWithoutAdmin, isAdminRoute } from './shared.js' type Args = { adminRoute: string config: SanitizedConfig defaultIDType: Payload['db']['defaultIDType'] + payload?: Payload route: string } @@ -22,7 +25,13 @@ type RouteInfo = { globalSlug?: string } -export function getRouteInfo({ adminRoute, config, defaultIDType, route }: Args): RouteInfo { +export function getRouteInfo({ + adminRoute, + config, + defaultIDType, + payload, + route, +}: Args): RouteInfo { if (isAdminRoute({ adminRoute, config, route })) { const routeWithoutAdmin = getRouteWithoutAdmin({ adminRoute, route }) const routeSegments = routeWithoutAdmin.split('/').filter(Boolean) @@ -30,15 +39,9 @@ export function getRouteInfo({ adminRoute, config, defaultIDType, route }: Args) const collectionSlug = entityType === 'collections' ? entitySlug : undefined const globalSlug = entityType === 'globals' ? entitySlug : undefined - const docID = - collectionSlug && createOrID !== 'create' - ? defaultIDType === 'number' - ? Number(createOrID) - : createOrID - : undefined - let collectionConfig: SanitizedCollectionConfig | undefined let globalConfig: SanitizedGlobalConfig | undefined + let idType = defaultIDType if (collectionSlug) { collectionConfig = config.collections.find((collection) => collection.slug === collectionSlug) @@ -48,6 +51,20 @@ export function getRouteInfo({ adminRoute, config, defaultIDType, route }: Args) globalConfig = config.globals.find((global) => global.slug === globalSlug) } + // If the collection has an ID field, we need to determine the type of the ID field + if (collectionConfig && payload) { + if (payload.collections?.[collectionSlug]) { + idType = payload.collections?.[collectionSlug].customIDType + } + } + + const docID = + collectionSlug && createOrID !== 'create' + ? idType === 'number' + ? Number(createOrID) + : createOrID + : undefined + return { collectionConfig, collectionSlug, diff --git a/packages/next/src/utilities/initPage/index.ts b/packages/next/src/utilities/initPage/index.ts index 520d0ce960d..934e9ee6aa9 100644 --- a/packages/next/src/utilities/initPage/index.ts +++ b/packages/next/src/utilities/initPage/index.ts @@ -149,6 +149,7 @@ export const initPage = async ({ adminRoute, config: payload.config, defaultIDType: payload.db.defaultIDType, + payload, route, })