- Resolve conflicts in analytics, consent, content, i18n, mcp and stats, keeping the docs fixes and the new code behaviour, verified against src - Translate the remaining 14 module pages, ipal-seo-check skill and script - Integrate the security-perf and SEO agent-guide text: getRobots, isPathVisible, Search & AI (DNS verification first, meta fields optional), sitemap index/cache/503, consentMode basic/advanced, policyVersion, globalOverrides, revalidatePath / buildGlobalRevalidateHook, authAccess, firstUserAdmin, allowCollectionMismatch, unknown-IP rate limit; stale claims fixed across AGENT.md, skills, frontend, developer guide, vibe - docsConsistency: pending list removed (all docs English); relative links now also check #anchors Co-Authored-By: Claude Opus 5.5 <[email protected]>
90 lines
4.1 KiB
Markdown
90 lines
4.1 KiB
Markdown
# notifications
|
|
|
|
Notification texts (action results) configured in the admin panel, per language, with a
|
|
fallback. Today it covers form result messages (`submitForm`),
|
|
with room for future contexts. The **Notifications** global is always built.
|
|
|
|
## Principle
|
|
|
|
The plugin returns a result CODE (`submitForm` returns `reason`), not text. This module
|
|
maps code → text from the panel (localized), with an English fallback per field.
|
|
The frontend gets a ready string and styles it as it likes (toast, inline, banner).
|
|
This way no message is hardcoded — everything goes through the panel.
|
|
|
|
## Config
|
|
|
|
No options — the **Notifications** global (slug `notifications`, panel group *Settings*) is always built. The editor manages
|
|
the texts in the panel (Notifications tab), grouped per context. Group `form`:
|
|
`success`, `error`, `rateLimited`, `turnstile`, `validation`, `consent`,
|
|
`notFound` and the multi-step form buttons: `next` ("Next"), `back` ("Back"),
|
|
`stepOf` ("Step {current} of {total}"). Every empty field → fallback (`NOTIFICATION_FALLBACK`, EN,
|
|
exported from `@intecion/ipal-kit`).
|
|
For forms: `getFormTexts(locale)` from `lib/content` = the `form` group in the given language.
|
|
|
|
## Helper — getNotificationTexts
|
|
|
|
Reads the texts from the global per language, with a fallback per field. The counterpart of `getConsentTexts`:
|
|
|
|
```ts
|
|
import { getNotificationTexts } from '@intecion/ipal-kit'
|
|
|
|
const notifications = await getNotificationTexts({ payload, locale }) // in lib/content: getFormTexts(locale) = .form
|
|
// notifications.form.error, notifications.form.success, ...
|
|
```
|
|
|
|
## Mapping the result — resolveFormMessage
|
|
|
|
The bridge between `submitForm` and the UI: takes the result and the texts, returns one message.
|
|
Interpolates `{field}` in the validation text. NEVER shows a raw exception
|
|
(`error` → a generic text, not the backend error message).
|
|
|
|
```ts
|
|
import { resolveFormMessage } from '@intecion/ipal-kit'
|
|
|
|
const result = await submitFormAction(...)
|
|
if (!result.success) {
|
|
setError(resolveFormMessage(result, notifications.form))
|
|
}
|
|
```
|
|
|
|
This replaces a hardcoded `Error: ${result.reason}` — now a friendly text from the panel,
|
|
per language.
|
|
|
|
## {field} interpolation
|
|
|
|
The `validation` text may contain `{field}` — it is replaced with the **technical name** of the field with
|
|
the error (`name`, not the label), only the first `{field}` occurrence; no name → empty string:
|
|
|
|
```
|
|
Panel: "Sprawdź pole {field} i spróbuj ponownie."
|
|
Result: "Sprawdź pole email i spróbuj ponownie."
|
|
```
|
|
|
|
## Adding new contexts
|
|
|
|
The `form` group is the first context. Further ones (`newsletter`, `system`) are added
|
|
the same way — a new group in `globals/Notifications/fields.ts` + a field in the types +
|
|
a fallback. `getNotificationTexts` resolves whatever exists.
|
|
|
|
## Access
|
|
|
|
The global has `read: () => true` — the texts are public (shown to end
|
|
users), so the frontend reads them without a session. Write: `editor+` (`adminOrEditor`). Unlike SiteIntegrations
|
|
(`read: isAdmin` — secrets live there).
|
|
|
|
## Turn off, override, extend
|
|
|
|
- **Turn off:** none — the `notifications` global is currently always added (also without the `forms` option).
|
|
- **Override texts:** in the panel, per language; empty field → `NOTIFICATION_FALLBACK` (EN).
|
|
The fallbacks cannot be swapped with a plugin option — apply your own default texts in the project
|
|
on the result of `getNotificationTexts` (e.g. `texts.form.error ||= '…'`).
|
|
- **Override access / hooks / admin:** `ipalKit({ globalOverrides: { notifications: … } })` — an object merges
|
|
`access`, `admin` and `hooks` key by key over the plugin's (e.g. let any logged-in user edit:
|
|
`{ notifications: { access: { update: authenticated } } }`), a function gets the global and returns the one to use.
|
|
- **Override mapping:** `resolveFormMessage` is optional — you can map `result.reason`
|
|
with your own switch.
|
|
- **Extend:** the global's fields are fixed in the plugin (no `ipalKit` option to add groups / fields);
|
|
for a project-only extra, a `globalOverrides.notifications` function can append fields, but
|
|
`getNotificationTexts` will not read them — a new shared context needs a change in the plugin
|
|
(`globals/Notifications/fields.ts`, types, fallback).
|