Admin panel in English and Polish, reworded per docs/dev/admin-ux.md
- admin-i18n module: AdminText { en, pl }, component texts under the ipal
namespace (project translations win), en + pl admin languages when the
project sets none (project's supportedLanguages wins)
- every plugin label, description, option, tab and group as { en, pl };
explicit labels instead of auto-labels; sentence case; glossary terms
- visible renames (slugs, names, data unchanged): Cookie banner, Form
messages, Privacy group, Search engines, Maintenance, Spam protection,
E-mail sending, stats nav link Overview (hidden without access)
- Polish visitor defaults by page locale: cookie banner, form messages,
validators, lightbox, accessibility widget; {field} uses the label
- fixes: e-mail status banner used Turnstile wording; developer words and
env var names out of editor messages; stats numbers/dates in the admin
language; test e-mail no longer says ipal-kit
- test/adminUx.test.ts: length limits, en + pl present, no developer words
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
eeac33ed2f
commit
6b46bc0c14
@@ -2,23 +2,31 @@ import type { Payload } from 'payload'
|
||||
|
||||
import type { IntegrationStatus } from './status.js'
|
||||
|
||||
import { turnstileKeyProblem } from '../turnstile/config.js'
|
||||
import { turnstileMissingKey } from '../turnstile/config.js'
|
||||
import { type IntegrationLabel, resolveLabel, serverText, STATUS_CODE_TEXTS } from './texts.js'
|
||||
|
||||
type Props = {
|
||||
/** Admin route, for the link. Default '/admin'. */
|
||||
adminRoute?: string
|
||||
/** Status groups to check: field name → label. */
|
||||
checks?: Record<string, string>
|
||||
/** Status groups to check: field name → label (one string, or one per language). */
|
||||
checks?: Record<string, IntegrationLabel>
|
||||
/** Injected by Payload into admin server components. */
|
||||
i18n?: { language?: string; t?: (key: never, vars?: Record<string, unknown>) => string }
|
||||
/** Injected by Payload into admin server components. */
|
||||
payload?: Payload
|
||||
}
|
||||
|
||||
const DEFAULT_CHECKS: Record<string, IntegrationLabel> = {
|
||||
emailStatus: { en: 'E-mail sending', pl: 'Wysyłka e-mail' },
|
||||
turnstileStatus: { en: 'Spam protection', pl: 'Ochrona przed spamem' },
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashboard alert (admin.components.beforeDashboard): lists integrations that
|
||||
* are currently failing, with a link to Site Integrations. Renders nothing when
|
||||
* are currently failing, with a link to Site integrations. Renders nothing when
|
||||
* everything is fine — and never throws (DB not ready → nothing).
|
||||
*/
|
||||
export async function IntegrationAlerts({ adminRoute = '/admin', checks = { emailStatus: 'Email', turnstileStatus: 'Turnstile' }, payload }: Props) {
|
||||
export async function IntegrationAlerts({ adminRoute = '/admin', checks = DEFAULT_CHECKS, i18n, payload }: Props) {
|
||||
if (!payload) {return null}
|
||||
let doc: Record<string, unknown>
|
||||
try {
|
||||
@@ -26,17 +34,26 @@ export async function IntegrationAlerts({ adminRoute = '/admin', checks = { emai
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
const i18nLike = i18n
|
||||
const language = i18n?.language
|
||||
const failing = Object.entries(checks)
|
||||
.map(([field, label]) => {
|
||||
const status = doc?.[field] as IntegrationStatus | undefined
|
||||
return { label, message: status?.state === 'degraded' ? (status.message ?? status.code ?? 'error') : null }
|
||||
if (status?.state !== 'degraded') {return { field, label: resolveLabel(label, language), message: null }}
|
||||
const key = status.code ? STATUS_CODE_TEXTS[status.code] : undefined
|
||||
const message = key ? serverText(i18nLike, key) : (status.message ?? status.code ?? serverText(i18nLike, 'alertsUnknownError'))
|
||||
return { field, label: resolveLabel(label, language), message }
|
||||
})
|
||||
.filter((x): x is { label: string; message: string } => x.message !== null)
|
||||
.filter((x): x is { field: string; label: string; message: string } => x.message !== null)
|
||||
// Configuration problems no request will ever record (nothing is verified
|
||||
// while Turnstile is off) — checked live from the saved keys.
|
||||
const keyProblem = turnstileKeyProblem(doc ?? {})
|
||||
if (keyProblem && !failing.some((f) => f.label === 'Turnstile')) {
|
||||
failing.push({ label: 'Turnstile', message: keyProblem })
|
||||
const missing = turnstileMissingKey(doc ?? {})
|
||||
if (missing && 'turnstileStatus' in checks && !failing.some((f) => f.field === 'turnstileStatus')) {
|
||||
failing.push({
|
||||
field: 'turnstileStatus',
|
||||
label: resolveLabel(checks.turnstileStatus, language),
|
||||
message: serverText(i18nLike, missing === 'secret' ? 'statusTurnstileNoSecretKey' : 'statusTurnstileNoSiteKey'),
|
||||
})
|
||||
}
|
||||
if (!failing.length) {return null}
|
||||
|
||||
@@ -51,16 +68,16 @@ export async function IntegrationAlerts({ adminRoute = '/admin', checks = { emai
|
||||
padding: '1rem 1.25rem',
|
||||
}}
|
||||
>
|
||||
<strong>Integration problem — the site still works, but something needs attention.</strong>
|
||||
<strong>{serverText(i18nLike, 'alertsHeading')}</strong>
|
||||
<ul style={{ margin: '0.5rem 0 0', paddingLeft: '1.2rem' }}>
|
||||
{failing.map(({ label, message }) => (
|
||||
<li key={label}>
|
||||
{failing.map(({ field, label, message }) => (
|
||||
<li key={field}>
|
||||
<strong>{label}:</strong> {message}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<a href={`${adminRoute.replace(/\/$/, '')}/globals/site-integrations`} style={{ display: 'inline-block', marginTop: '0.5rem' }}>
|
||||
Open Site Integrations →
|
||||
{serverText(i18nLike, 'alertsLink')}
|
||||
</a>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user