added validation for forms, sensitive text fields have been masked
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import type { BasePayload } from 'payload'
|
||||
|
||||
import type { NotificationsData, NotificationTexts } from './types.js'
|
||||
|
||||
import { getGlobal } from '../payload/index.js'
|
||||
import { NOTIFICATION_FALLBACK } from './defaults.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 async function getNotificationTexts({
|
||||
locale,
|
||||
payload,
|
||||
}: GetNotificationTextsArgs): Promise<NotificationTexts> {
|
||||
const g = await getGlobal<NotificationsData>(payload, 'notifications', { locale })
|
||||
|
||||
const f = g.form ?? {}
|
||||
const fb = NOTIFICATION_FALLBACK.form
|
||||
|
||||
return {
|
||||
form: {
|
||||
consent: f.consent || fb.consent,
|
||||
error: f.error || fb.error,
|
||||
notFound: f.notFound || fb.notFound,
|
||||
rateLimited: f.rateLimited || fb.rateLimited,
|
||||
success: f.success || fb.success,
|
||||
turnstile: f.turnstile || fb.turnstile,
|
||||
validation: f.validation || fb.validation,
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user