payload.config.ts used explicit .js extensions on local imports which Turbopack and webpack cannot resolve to .ts files without extensionAliases config. Revert to extension-less imports (original pattern from first Payload commit) that both bundlers handle natively. Also fix two TypeScript strict-mode errors: - seed/route.ts: doc.id (number) cast to string via String() instead of `as string` - getHomeData.ts: Payload HomePage vs HomePageGlobal cast via `as unknown as` Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { cache } from 'react'
|
|
import { getPayload } from 'payload'
|
|
import configPromise from '@payload-config'
|
|
import type { HomePageGlobal, LocationCMS, ReviewCMS, BirthdayPackageCMS } from '@/types/globals'
|
|
|
|
export interface HomeData {
|
|
home: HomePageGlobal | null
|
|
locations: LocationCMS[]
|
|
reviews: ReviewCMS[]
|
|
birthdayPackages: BirthdayPackageCMS[]
|
|
}
|
|
|
|
export const getHomeData = cache(async (): Promise<HomeData> => {
|
|
try {
|
|
const payload = await getPayload({ config: configPromise })
|
|
|
|
const [home, locResult, revResult, pkgResult] = await Promise.all([
|
|
payload.findGlobal({ slug: 'home-page' }) as unknown as Promise<HomePageGlobal>,
|
|
payload.find({
|
|
collection: 'locations',
|
|
where: { showOnHome: { equals: true } },
|
|
sort: 'sort',
|
|
limit: 20,
|
|
overrideAccess: true,
|
|
}),
|
|
payload.find({
|
|
collection: 'reviews',
|
|
where: { showOnHome: { equals: true } },
|
|
sort: 'sort',
|
|
limit: 20,
|
|
overrideAccess: true,
|
|
}),
|
|
payload.find({
|
|
collection: 'birthday-packages',
|
|
sort: 'sort',
|
|
limit: 10,
|
|
overrideAccess: true,
|
|
}),
|
|
])
|
|
|
|
return {
|
|
home,
|
|
locations: locResult.docs as unknown as LocationCMS[],
|
|
reviews: revResult.docs as unknown as ReviewCMS[],
|
|
birthdayPackages: pkgResult.docs as unknown as BirthdayPackageCMS[],
|
|
}
|
|
} catch {
|
|
return { home: null, locations: [], reviews: [], birthdayPackages: [] }
|
|
}
|
|
})
|
|
|
|
export function getHeaderLocations() {
|
|
return cache(async (): Promise<LocationCMS[]> => {
|
|
try {
|
|
const payload = await getPayload({ config: configPromise })
|
|
const result = await payload.find({
|
|
collection: 'locations',
|
|
where: { showInMenu: { equals: true } },
|
|
sort: 'sort',
|
|
limit: 20,
|
|
overrideAccess: true,
|
|
})
|
|
return result.docs as unknown as LocationCMS[]
|
|
} catch {
|
|
return []
|
|
}
|
|
})()
|
|
}
|