WIP: form attachments (e-mail only) — core, endpoint, Graph large upload
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
0ba0014ed5
commit
6003b3d7d7
@@ -12,6 +12,11 @@ export const NOTIFICATION_FALLBACK: NotificationTexts = {
|
||||
back: 'Back',
|
||||
consent: 'Accept the privacy policy to send the form.',
|
||||
error: 'The form could not be sent. Please try again in a moment.',
|
||||
fileCount: 'Attach at most {max} files in "{field}".',
|
||||
fileNotSent: 'We could not send your file. Try again, or send it by e-mail.',
|
||||
fileRemove: 'Remove {file}',
|
||||
fileTooLarge: '"{file}" is too large. The limit is {max} MB.',
|
||||
fileType: '"{file}" is not an accepted file type. Accepted: {types}.',
|
||||
next: 'Next',
|
||||
notFound: 'This form is no longer available.',
|
||||
rateLimited: 'Too many attempts. Please wait a moment and try again.',
|
||||
@@ -29,6 +34,11 @@ export const NOTIFICATION_FALLBACK_PL: NotificationTexts = {
|
||||
back: 'Wstecz',
|
||||
consent: 'Zaakceptuj politykę prywatności, aby wysłać formularz.',
|
||||
error: 'Nie udało się wysłać formularza. Spróbuj ponownie za chwilę.',
|
||||
fileCount: 'W polu „{field}” można dodać najwyżej {max} plików.',
|
||||
fileNotSent: 'Nie udało się wysłać pliku. Spróbuj ponownie lub wyślij go e-mailem.',
|
||||
fileRemove: 'Usuń {file}',
|
||||
fileTooLarge: 'Plik „{file}” jest za duży. Limit to {max} MB.',
|
||||
fileType: 'Plik „{file}” ma niedozwolony typ. Dozwolone: {types}.',
|
||||
next: 'Dalej',
|
||||
notFound: 'Ten formularz nie jest już dostępny.',
|
||||
rateLimited: 'Zbyt wiele prób. Odczekaj chwilę i spróbuj ponownie.',
|
||||
|
||||
@@ -32,6 +32,11 @@ export async function getNotificationTexts({
|
||||
back: f.back || fb.back,
|
||||
consent: f.consent || fb.consent,
|
||||
error: f.error || fb.error,
|
||||
fileCount: f.fileCount || fb.fileCount,
|
||||
fileNotSent: f.fileNotSent || fb.fileNotSent,
|
||||
fileRemove: f.fileRemove || fb.fileRemove,
|
||||
fileTooLarge: f.fileTooLarge || fb.fileTooLarge,
|
||||
fileType: f.fileType || fb.fileType,
|
||||
next: f.next || fb.next,
|
||||
notFound: f.notFound || fb.notFound,
|
||||
rateLimited: f.rateLimited || fb.rateLimited,
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
import type { SubmitFormResult } from '../forms/index.js'
|
||||
import type { FormNotificationTexts } from './types.js'
|
||||
|
||||
/**
|
||||
* The texts resolveFormMessage needs. The File-field texts are optional, so an
|
||||
* object written before they existed still fits (the field or general text is used).
|
||||
*/
|
||||
export type FormMessageTexts = { [K in 'fileCount' | 'fileNotSent' | 'fileRemove' | 'fileTooLarge' | 'fileType']?: string } & Omit<
|
||||
FormNotificationTexts,
|
||||
'fileCount' | 'fileNotSent' | 'fileRemove' | 'fileTooLarge' | 'fileType'
|
||||
>
|
||||
|
||||
/**
|
||||
* Maps a submitForm result to the user-facing message, interpolating {field}
|
||||
* with the field's label (its key when the form has no label) for validation
|
||||
@@ -12,12 +21,14 @@ import type { FormNotificationTexts } from './types.js'
|
||||
* Never surfaces raw backend/exception detail — 'error' maps to a friendly
|
||||
* generic message, not the thrown error's text (which could leak internals).
|
||||
*/
|
||||
export function resolveFormMessage(result: SubmitFormResult, texts: FormNotificationTexts): string {
|
||||
export function resolveFormMessage(result: SubmitFormResult, texts: FormMessageTexts): string {
|
||||
if (result.success) {return texts.success}
|
||||
|
||||
switch (result.reason) {
|
||||
case 'consent':
|
||||
return texts.consent
|
||||
case 'delivery':
|
||||
return texts.fileNotSent ?? texts.error
|
||||
case 'not_found':
|
||||
return texts.notFound
|
||||
case 'rate_limited':
|
||||
@@ -27,6 +38,15 @@ export function resolveFormMessage(result: SubmitFormResult, texts: FormNotifica
|
||||
case 'validation': {
|
||||
// {field} → the label the visitor sees; no single field at fault → the generic error.
|
||||
const field = result.label || result.field
|
||||
const fill = (text: string) =>
|
||||
text
|
||||
.replace('{file}', result.file ?? '')
|
||||
.replace('{max}', result.max === undefined ? '' : String(result.max))
|
||||
.replace('{types}', result.types ?? '')
|
||||
.replace('{field}', field ?? '')
|
||||
if (result.kind === 'file_too_large' && texts.fileTooLarge) {return fill(texts.fileTooLarge)}
|
||||
if (result.kind === 'file_type' && texts.fileType) {return fill(texts.fileType)}
|
||||
if (result.kind === 'file_count' && texts.fileCount) {return fill(texts.fileCount)}
|
||||
return field ? texts.validation.replace('{field}', field) : texts.error
|
||||
}
|
||||
case 'error':
|
||||
|
||||
@@ -10,6 +10,16 @@ export type FormNotificationTexts = {
|
||||
/** Shown when a required GDPR consent checkbox was left unchecked. */
|
||||
consent: string
|
||||
error: string
|
||||
/** File field: too many files, with {field} and {max}. */
|
||||
fileCount: string
|
||||
/** File field: the e-mail with the file could not be sent — the visitor has to send it again. */
|
||||
fileNotSent: string
|
||||
/** File field: the button that removes a selected file, with {file}. */
|
||||
fileRemove: string
|
||||
/** File field: a file over the limit, with {file} and {max} (MB). */
|
||||
fileTooLarge: string
|
||||
/** File field: a file of a type the field does not accept, with {file} and {types}. */
|
||||
fileType: string
|
||||
/** Step-by-step forms: "Next" button. */
|
||||
next: string
|
||||
notFound: string
|
||||
|
||||
Reference in New Issue
Block a user