mirror of
https://github.com/complexcaresolutions/cms.c2sgmbh.git
synced 2026-03-17 17:24:12 +00:00
fix: form submission hooks — tenant propagation + email notification
- FormSubmissionsOverrides: fields must be a function (not array) for the form-builder plugin to merge them with defaultFields - setSubmissionTenant: add overrideAccess for unauthenticated submissions - sendFormNotification: handle populated form object (extract ID), add overrideAccess for tenant SMTP lookup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5e223cd7fb
commit
d90657c2cf
3 changed files with 30 additions and 17 deletions
|
|
@ -1,29 +1,22 @@
|
|||
// src/collections/FormSubmissionsOverrides.ts
|
||||
|
||||
import type { CollectionConfig } from 'payload'
|
||||
import type { CollectionConfig, Field } from 'payload'
|
||||
|
||||
/**
|
||||
* FormSubmissions Overrides
|
||||
*
|
||||
* Erweitert die vom formBuilderPlugin erstellte FormSubmissions Collection um:
|
||||
* - Tenant-Zuweisung (automatisch vom Formular)
|
||||
* - Status-Workflow (neu → in Bearbeitung → erledigt)
|
||||
* - Interne Notizen
|
||||
* - Zuständigkeits-Zuweisung
|
||||
* - Verbesserte Admin-Ansicht
|
||||
*
|
||||
* WICHTIG: fields MUSS eine Funktion sein, da das formBuilderPlugin
|
||||
* ein Array stillschweigend ignoriert und nur defaultFields verwendet.
|
||||
*/
|
||||
export const formSubmissionOverrides: Partial<CollectionConfig> = {
|
||||
admin: {
|
||||
useAsTitle: 'id',
|
||||
group: 'Formulare',
|
||||
defaultColumns: ['id', 'form', 'status', 'assignedTo', 'createdAt'],
|
||||
description: 'Eingegangene Formular-Einsendungen',
|
||||
listSearchableFields: ['id', 'status'],
|
||||
},
|
||||
labels: {
|
||||
singular: 'Formular-Einsendung',
|
||||
plural: 'Formular-Einsendungen',
|
||||
},
|
||||
fields: [
|
||||
|
||||
const customFields: Field[] = [
|
||||
// Tenant (automatisch vom Formular übernommen via setSubmissionTenant Hook)
|
||||
{
|
||||
name: 'tenant',
|
||||
|
|
@ -222,5 +215,22 @@ export const formSubmissionOverrides: Partial<CollectionConfig> = {
|
|||
readOnly: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
]
|
||||
|
||||
export const formSubmissionOverrides: Partial<CollectionConfig> = {
|
||||
admin: {
|
||||
useAsTitle: 'id',
|
||||
group: 'Formulare',
|
||||
defaultColumns: ['id', 'form', 'tenant', 'status', 'assignedTo', 'createdAt'],
|
||||
description: 'Eingegangene Formular-Einsendungen',
|
||||
listSearchableFields: ['id', 'status'],
|
||||
},
|
||||
labels: {
|
||||
singular: 'Formular-Einsendung',
|
||||
plural: 'Formular-Einsendungen',
|
||||
},
|
||||
fields: (({ defaultFields }: { defaultFields: Field[] }) => [
|
||||
...defaultFields,
|
||||
...customFields,
|
||||
]) as unknown as Field[],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,11 +38,13 @@ export const sendFormNotification: CollectionAfterChangeHook = async ({
|
|||
const { payload } = req
|
||||
|
||||
try {
|
||||
// Form laden mit Details
|
||||
// Form laden mit Details — doc.form kann bereits populated sein (Objekt statt ID)
|
||||
const formId = typeof doc.form === 'object' ? doc.form?.id : doc.form
|
||||
const form = (await payload.findByID({
|
||||
collection: 'forms',
|
||||
id: doc.form,
|
||||
id: formId,
|
||||
depth: 1,
|
||||
overrideAccess: true,
|
||||
})) as FormDocument | null
|
||||
|
||||
if (!form) {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ export const setSubmissionTenant: CollectionBeforeChangeHook = async ({
|
|||
collection: 'forms',
|
||||
id: formId,
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
})) as unknown as FormWithTenant
|
||||
|
||||
if (form?.tenant) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue