Under construction mode (developer tool)
Site Settings -> Under construction: a switch, 'Pages still available' and notice texts. When on, only the homepage and the chosen pages open (every language); other addresses redirect to the homepage with the notice (createPageRoute redirect option), and <ConstructionNotice> cancels clicks on links to blocked pages and shows the notice. getConstructionMode(locale). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import type { Field } from 'payload'
|
||||
|
||||
const whenEnabled = (_: unknown, siblingData: { enabled?: boolean } | undefined) => Boolean(siblingData?.enabled)
|
||||
|
||||
/**
|
||||
* Site Settings → "Under construction" tab: a developer tool for a site that
|
||||
* isn't finished. When enabled, only the homepage and the chosen pages are
|
||||
* reachable — any other address redirects to the homepage with a notice, and a
|
||||
* link to another page shows the notice instead of navigating. One rule for
|
||||
* every visitor (pages stay static, there is no per-user check).
|
||||
*/
|
||||
export function buildConstructionFields(pagesSlug: string): Field[] {
|
||||
return [
|
||||
{
|
||||
name: 'construction',
|
||||
type: 'group',
|
||||
admin: { hideGutter: true },
|
||||
fields: [
|
||||
{
|
||||
name: 'enabled',
|
||||
type: 'checkbox',
|
||||
admin: {
|
||||
description:
|
||||
'Only the homepage and the pages below can be opened. Other addresses redirect to the homepage with the notice; links to other pages show it instead of navigating.',
|
||||
},
|
||||
defaultValue: false,
|
||||
label: 'Site under construction',
|
||||
},
|
||||
{
|
||||
name: 'allowedPages',
|
||||
type: 'relationship',
|
||||
admin: { condition: whenEnabled, description: 'The homepage is always available.' },
|
||||
hasMany: true,
|
||||
label: 'Pages still available',
|
||||
relationTo: pagesSlug as never,
|
||||
},
|
||||
{ name: 'title', type: 'text', admin: { condition: whenEnabled }, label: 'Notice title', localized: true },
|
||||
{ name: 'message', type: 'textarea', admin: { condition: whenEnabled }, label: 'Notice text', localized: true },
|
||||
{ name: 'buttonLabel', type: 'text', admin: { condition: whenEnabled }, label: 'Close button label', localized: true },
|
||||
],
|
||||
label: false,
|
||||
},
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user