- AGENT.md: §7 full capability catalog (need → import), §0b/§3/§6 on RenderForm, SiteProviders, createPageRoute, re-exported routes, plugin section fields, resolveLink/resolveNav - PROGRAMISTA §2.4, §2.7–2.8 rewritten; §6 items 28–33 (28: FormRenderer leaked the Emails tab) - forms, links, blocks, pages, consent, turnstile, notifications, seo, mcp, i18n, deployment docs - ipal-form: RenderForm block, formClasses, CustomForm example (FormRenderer template removed), seed template handles steps and option labels per language - ipal-nav, ipal-block, ipal-setup, ipal-upgrade, ipal-seo-check, ipal-consent-check, vibe.md - ipal-audit: re-export routes and SiteProviders satisfy the mandatory set; flags form-engine copies, project section fields / navigation, server entries in client components - test/docsConsistency: docs imports exist in code; every public export is documented - CHANGELOG 1.9.2 Co-Authored-By: Claude Opus 5.5 <[email protected]>
72 lines
2.6 KiB
Markdown
72 lines
2.6 KiB
Markdown
# notifications
|
|
|
|
Teksty powiadomień (wyniki akcji) konfigurowane w panelu, per język, z
|
|
fallbackiem. Na dziś obsługuje komunikaty wyników formularza (`submitForm`),
|
|
z miejscem na przyszłe konteksty. Global **Notifications**, budowany zawsze.
|
|
|
|
## Zasada
|
|
|
|
Plugin daje KOD wyniku (`submitForm` zwraca `reason`), nie tekst. Ten moduł
|
|
mapuje kod → tekst z panelu (localized), z fallbackiem angielskim per pole.
|
|
Front dostaje gotowy string i styluje go jak chce (toast, inline, banner).
|
|
Dzięki temu żaden komunikat nie jest zaszyty w kodzie — wszystko przez panel.
|
|
|
|
## Config
|
|
|
|
Brak opcji — global **Notifications** jest zawsze budowany. Edytor zarządza
|
|
tekstami w panelu (karta Notifications), grupowane per kontekst. Grupa `form`:
|
|
`success`, `error`, `rateLimited`, `turnstile`, `validation`, `consent`,
|
|
`notFound` oraz przyciski formularzy krokowych: `next` („Dalej”), `back` („Wstecz”),
|
|
`stepOf` („Krok {current} z {total}”). Każde pole puste → fallback (NOTIFICATION_FALLBACK, EN).
|
|
Dla formularzy: `getFormTexts(locale)` z `lib/content` = grupa `form` w danym języku.
|
|
|
|
## Helper — getNotificationTexts
|
|
|
|
Pobiera teksty z globala per język, fallback per pole. Analog `getConsentTexts`:
|
|
|
|
```ts
|
|
import { getNotificationTexts } from '@intecion/ipal-kit'
|
|
|
|
const notifications = await getNotificationTexts({ payload, locale }) // w lib/content: getFormTexts(locale) = .form
|
|
// notifications.form.error, notifications.form.success, ...
|
|
```
|
|
|
|
## Mapowanie wyniku — resolveFormMessage
|
|
|
|
Most między `submitForm` a UI: bierze wynik i teksty, zwraca jeden komunikat.
|
|
Interpoluje `{field}` w walidacji. NIGDY nie pokazuje surowego wyjątku
|
|
(`error` → generyczny tekst, nie treść błędu backendu).
|
|
|
|
```ts
|
|
import { resolveFormMessage } from '@intecion/ipal-kit'
|
|
|
|
const result = await submitFormAction(...)
|
|
if (!result.success) {
|
|
setError(resolveFormMessage(result, notifications.form))
|
|
}
|
|
```
|
|
|
|
To zastępuje sztywne `Błąd: ${result.reason}` — teraz przyjazny tekst z panelu,
|
|
per język.
|
|
|
|
## Interpolacja {field}
|
|
|
|
Tekst `validation` może zawierać `{field}` — podstawia się nazwa pola z błędem:
|
|
|
|
```
|
|
Panel: "Sprawdź pole {field} i spróbuj ponownie."
|
|
Wynik: "Sprawdź pole email i spróbuj ponownie."
|
|
```
|
|
|
|
## Rozszerzanie o nowe konteksty
|
|
|
|
Grupa `form` to pierwszy kontekst. Kolejne (`newsletter`, `system`) dodaje się
|
|
tak samo — nowa grupa w `globals/Notifications/fields.ts` + pole w typach +
|
|
fallback. `getNotificationTexts` resolwuje, co istnieje.
|
|
|
|
## Dostęp
|
|
|
|
Global ma `read: () => true` — teksty są publiczne (pokazywane użytkownikom
|
|
końcowym), więc front czyta je bez sesji. Inaczej niż SiteIntegrations
|
|
(`read: isAdmin` — tam sekrety).
|