fix(cms): resolve internal CTA links per locale via a page selector (MITHOME-123)
The home hero CTA stored a free-text href "/kapcsolat" that predated the locale-prefixed routing (MITHOME-114), so the main call-to-action led to a 404. Internal targets were typed by hand and could never follow the locale or its translated slug. CTA links now choose between an internal page (home/about/services/ contact/privacy/terms) and an external URL. Page links are resolved per request with localePath(), giving /hu/kapcsolat and /en/contact; external links (webmail) keep their localized href. A Payload migration converts existing internal paths to page links on the published global and every draft/version, idempotently and independent of the locale migration's order. The global-doc iteration shared with MITHOME-111 moved to src/lib/migrate-global-docs.ts; the JSON seed emits the new shape too. Verified on a copy of the staging DB: both migrations ran on startup, /hu and /en CTAs point to their contact pages (200), webmail unchanged, admin shows the selector, toggles the fields and blocks publishing a URL link without a URL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
38d34fab4c
commit
e8ff7adeb5
@@ -0,0 +1,63 @@
|
||||
import type { GroupField } from 'payload'
|
||||
|
||||
import { CTA_PAGES, type CtaPage } from '../../lib/cta-link'
|
||||
|
||||
const PAGE_LABELS: Record<CtaPage, string> = {
|
||||
home: 'Főoldal',
|
||||
about: 'Rólunk',
|
||||
services: 'Szolgáltatások',
|
||||
contact: 'Kapcsolat',
|
||||
privacy: 'Adatvédelem',
|
||||
terms: 'Felhasználási feltételek',
|
||||
}
|
||||
|
||||
type Sibling = { linkType?: string } | undefined
|
||||
|
||||
const isPageLink = (sibling: Sibling) => (sibling?.linkType ?? 'page') === 'page'
|
||||
|
||||
/**
|
||||
* MITHOME-123: CTA button = localized text + either an internal page
|
||||
* (resolved per locale by src/lib/cta-link.ts) or an external URL.
|
||||
*
|
||||
* WHY custom `validate` instead of `required`: `page` and `href` are only
|
||||
* required for their own link type; the other one is hidden and empty.
|
||||
* DECISION: `href` stays localized (MITHOME-111) — an external target may
|
||||
* differ per language; `linkType`/`page` are shared across locales.
|
||||
*/
|
||||
export function ctaLinkGroup(name: string): GroupField {
|
||||
return {
|
||||
name,
|
||||
type: 'group',
|
||||
fields: [
|
||||
{ name: 'text', type: 'text', required: true, localized: true },
|
||||
{
|
||||
name: 'linkType',
|
||||
type: 'radio',
|
||||
required: true,
|
||||
defaultValue: 'page',
|
||||
options: [
|
||||
{ label: 'Belső oldal', value: 'page' },
|
||||
{ label: 'Külső URL', value: 'url' },
|
||||
],
|
||||
admin: { layout: 'horizontal' },
|
||||
},
|
||||
{
|
||||
name: 'page',
|
||||
type: 'select',
|
||||
options: CTA_PAGES.map((value) => ({ label: PAGE_LABELS[value], value })),
|
||||
admin: { condition: (_data, sibling) => isPageLink(sibling) },
|
||||
validate: (value: unknown, { siblingData }: { siblingData: Sibling }) =>
|
||||
!isPageLink(siblingData) || Boolean(value) || 'Válassz oldalt.',
|
||||
},
|
||||
{
|
||||
name: 'href',
|
||||
type: 'text',
|
||||
localized: true,
|
||||
admin: { condition: (_data, sibling) => !isPageLink(sibling) },
|
||||
validate: (value: unknown, { siblingData }: { siblingData: Sibling }) =>
|
||||
isPageLink(siblingData) || Boolean(value) || 'Add meg az URL-t.',
|
||||
},
|
||||
{ name: 'external', type: 'checkbox', defaultValue: false },
|
||||
],
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user