From 00c3548272f9eae29bbfbfbdc126a7fe932763a3 Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Mon, 8 Jun 2026 14:12:51 +0100 Subject: [PATCH] fix(dynozavry): fetch heroBackground from locations collection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit heroBgUrl was never populated — page.tsx queried only the dinosaur-page global and didn't read the Location's heroBackground upload field. Now fetches the locations collection in parallel and passes heroBgUrl to DinoPageContent, which already handles the conditional hero-bg render. Co-Authored-By: Claude Sonnet 4.6 --- src/app/(frontend)/lokatsii/dynozavry/page.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/app/(frontend)/lokatsii/dynozavry/page.tsx b/src/app/(frontend)/lokatsii/dynozavry/page.tsx index 2f299d4..0845382 100644 --- a/src/app/(frontend)/lokatsii/dynozavry/page.tsx +++ b/src/app/(frontend)/lokatsii/dynozavry/page.tsx @@ -3,7 +3,7 @@ import { getPayload } from 'payload' import configPromise from '@payload-config' import { DinoPageContent } from '@/components/sections/DinoPageContent' import { RefreshRouteOnSave } from '@/components/cms/RefreshRouteOnSave' -import type { Media } from '@/payload-types' +import type { Media, Location } from '@/payload-types' export const revalidate = 60 @@ -63,10 +63,22 @@ export async function generateMetadata(): Promise { export default async function DinosaurPage() { let data: DinoPageData = {} + let heroBgUrl: string | null = null try { const payload = await getPayload({ config: configPromise }) - const raw = await payload.findGlobal({ slug: 'dinosaur-page' as never, overrideAccess: true }) + const [raw, locationResult] = await Promise.all([ + payload.findGlobal({ slug: 'dinosaur-page' as never, overrideAccess: true }), + payload.find({ + collection: 'locations', + where: { slug: { equals: 'dynozavry' } }, + limit: 1, + depth: 1, + }), + ]) data = raw as unknown as DinoPageData + const loc = locationResult.docs[0] as Location | undefined + const bg = loc?.heroBackground + if (bg && typeof bg !== 'number') heroBgUrl = (bg as Media).url ?? null } catch { // DB unavailable at build time — render with fallbacks; ISR will hydrate at runtime } @@ -114,6 +126,7 @@ export default async function DinosaurPage() { statLabel={data.heroStatLabel} features={features && features.length > 0 ? features : undefined} heroImageUrl={mediaUrl(data.heroImage)} + heroBgUrl={heroBgUrl} dinos={dinos && dinos.length >= 12 ? dinos : undefined} galleryImages={galleryImages && galleryImages.length >= 4 ? galleryImages : undefined} activitiesTitle={data.activitiesTitle}