import type { Field } from 'payload' const whenEnabled = (_: unknown, siblingData: { enabled?: boolean } | undefined) => Boolean(siblingData?.enabled) /** * Site settings → "Maintenance" tab (maintenance mode) 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: { en: 'Visitors can open only the homepage and the pages below; other links show a notice.', pl: 'Odwiedzający mogą otworzyć tylko stronę główną i strony poniżej; inne linki pokazują komunikat.', }, }, defaultValue: false, label: { en: 'Maintenance mode', pl: 'Tryb prac technicznych' }, }, { name: 'allowedPages', type: 'relationship', admin: { condition: whenEnabled, description: { en: 'The homepage is always available.', pl: 'Strona główna jest zawsze dostępna.' }, }, hasMany: true, label: { en: 'Available pages', pl: 'Dostępne strony' }, relationTo: pagesSlug as never, }, { name: 'title', type: 'text', admin: { condition: whenEnabled }, label: { en: 'Notice title', pl: 'Tytuł komunikatu' }, localized: true, }, { name: 'message', type: 'textarea', admin: { condition: whenEnabled }, label: { en: 'Notice text', pl: 'Treść komunikatu' }, localized: true, }, { name: 'buttonLabel', type: 'text', admin: { condition: whenEnabled, description: { en: 'Leave empty to show a × sign.', pl: 'Zostaw puste, aby pokazać znak ×.', }, placeholder: { en: 'Close', pl: 'Zamknij' }, }, label: { en: 'Close button label', pl: 'Etykieta przycisku zamknięcia' }, localized: true, }, ], label: false, }, ] }