Compare commits
2
Commits
2215766940
..
v1.0.5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
81fa409513 | ||
|
|
90068c7952 |
+13
@@ -0,0 +1,13 @@
|
|||||||
|
import type { Field } from 'payload';
|
||||||
|
/**
|
||||||
|
* Fields for the Notifications global — localized user-facing texts for action
|
||||||
|
* results (form submission outcomes, and future contexts). Every text is
|
||||||
|
* localized: true so each language has its own value. Empty fields fall back to
|
||||||
|
* built-in English defaults (see modules/notifications/defaults).
|
||||||
|
*
|
||||||
|
* Grouped per context. `form` holds the outcomes of submitForm; more groups
|
||||||
|
* (e.g. `newsletter`, `system`) can be added the same way without touching
|
||||||
|
* consumers — getNotificationTexts resolves whatever exists, falling back
|
||||||
|
* per field.
|
||||||
|
*/
|
||||||
|
export declare const notificationsFields: Field[];
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
import type { GlobalConfig } from 'payload';
|
||||||
|
/**
|
||||||
|
* Builds the Notifications global — localized action-result texts. Readable by
|
||||||
|
* any authenticated panel user; server-side helpers read it with overrideAccess
|
||||||
|
* so the frontend can resolve texts without a session.
|
||||||
|
*/
|
||||||
|
export declare function buildNotifications(): GlobalConfig;
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import type { TextFieldClientComponent } from 'payload';
|
||||||
|
export declare const MaskedField: TextFieldClientComponent;
|
||||||
|
export default MaskedField;
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
import type { NotificationTexts } from './types.js';
|
||||||
|
/**
|
||||||
|
* Built-in English fallbacks, used per field when the Notifications global
|
||||||
|
* leaves a text empty. Same philosophy as consent FALLBACK: the site works out
|
||||||
|
* of the box, editors override per locale as needed.
|
||||||
|
*/
|
||||||
|
export declare const NOTIFICATION_FALLBACK: NotificationTexts;
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import type { BasePayload } from 'payload';
|
||||||
|
import type { NotificationTexts } from './types.js';
|
||||||
|
type GetNotificationTextsArgs = {
|
||||||
|
/** Active locale — selects the language variant of each text. */
|
||||||
|
locale?: string;
|
||||||
|
payload: BasePayload;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Resolves notification texts from the Notifications global, falling back to
|
||||||
|
* English defaults per field. Mirrors getConsentTexts: one read, per-field
|
||||||
|
* fallback, locale-aware. The frontend maps a submitForm result code to the
|
||||||
|
* matching text and styles it however it likes (toast, inline, banner).
|
||||||
|
*/
|
||||||
|
export declare function getNotificationTexts({ locale, payload, }: GetNotificationTextsArgs): Promise<NotificationTexts>;
|
||||||
|
export {};
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
export { NOTIFICATION_FALLBACK } from './defaults.js';
|
||||||
|
export { getNotificationTexts } from './getNotificationTexts.js';
|
||||||
|
export { resolveFormMessage } from './resolveFormMessage.js';
|
||||||
|
export type { FormNotificationTexts, NotificationsData, NotificationTexts } from './types.js';
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import type { SubmitFormResult } from '../forms/index.js';
|
||||||
|
import type { FormNotificationTexts } from './types.js';
|
||||||
|
/**
|
||||||
|
* Maps a submitForm result to the user-facing message, interpolating {field}
|
||||||
|
* for validation errors. This is the bridge the frontend uses: it gets a result
|
||||||
|
* code from submitForm and the resolved texts from getNotificationTexts, and
|
||||||
|
* this turns them into one string to display. Keeping the mapping here means the
|
||||||
|
* frontend never hard-codes messages or knows about result codes.
|
||||||
|
*
|
||||||
|
* Never surfaces raw backend/exception detail — 'error' maps to a friendly
|
||||||
|
* generic message, not the thrown error's text (which could leak internals).
|
||||||
|
*/
|
||||||
|
export declare function resolveFormMessage(result: SubmitFormResult, texts: FormNotificationTexts): string;
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Resolved notification texts, ready for the frontend. Grouped per context;
|
||||||
|
* `form` maps submitForm result codes to user-facing messages.
|
||||||
|
*/
|
||||||
|
export type FormNotificationTexts = {
|
||||||
|
success: string;
|
||||||
|
error: string;
|
||||||
|
rateLimited: string;
|
||||||
|
turnstile: string;
|
||||||
|
/** May contain the {field} placeholder — resolve with resolveValidationText. */
|
||||||
|
validation: string;
|
||||||
|
/** Shown when a required GDPR consent checkbox was left unchecked. */
|
||||||
|
consent: string;
|
||||||
|
notFound: string;
|
||||||
|
};
|
||||||
|
export type NotificationTexts = {
|
||||||
|
form: FormNotificationTexts;
|
||||||
|
};
|
||||||
|
/** Raw shape read from the Notifications global (all fields optional). */
|
||||||
|
export type NotificationsData = {
|
||||||
|
form?: Partial<FormNotificationTexts>;
|
||||||
|
};
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@intecion/ipal-kit",
|
"name": "@intecion/ipal-kit",
|
||||||
"version": "1.0.3",
|
"version": "1.0.5",
|
||||||
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
|
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
Reference in New Issue
Block a user