Fixed turnstile

This commit is contained in:
2026-10-15 15:27:43 +02:00
parent 7ef7927e38
commit 3bab8a0697
58 changed files with 1182 additions and 322 deletions
@@ -1,5 +1,7 @@
import type { Field } from 'payload'
import { buildIntegrationStatusBanner, buildIntegrationStatusField } from '../../../modules/integrations/status.js'
/**
* Cloudflare Turnstile credentials.
*
@@ -9,6 +11,8 @@ import type { Field } from 'payload'
* so they remain editable in the admin panel.
*/
export const turnstileFields: Field[] = [
// Status written by the server when it verifies a form (checkTurnstile) — banner on this tab.
buildIntegrationStatusBanner('turnstileStatus', 'Turnstile'),
{
name: 'turnstileSiteKey',
type: 'text',
@@ -27,4 +31,5 @@ export const turnstileFields: Field[] = [
},
},
},
buildIntegrationStatusField('turnstileStatus'),
]
+17 -5
View File
@@ -21,10 +21,6 @@ type BuildSiteIntegrationsArgs = {
* impossible to enter.)
*
* Unnamed tabs keep data flat (siteIntegrations.ga4MeasurementId).
*
* Note: R2 storage credentials are NOT here — storage is infrastructure and
* binds at boot, so its config lives in .env (R2_BUCKET, R2_ENDPOINT, ...),
* consumed by buildR2Storage. See docs/storage.md.
*/
export function buildSiteIntegrations({
additionalFields,
@@ -47,10 +43,26 @@ export function buildSiteIntegrations({
{ fields: analyticsFields, label: 'Analytics' },
{ fields: turnstileFields, label: 'Turnstile' },
{ fields: smtpFields, label: 'SMTP' },
...(additionalFields?.length ? [{ fields: additionalFields, label: 'Custom' }] : []),
...(additionalFields?.length
? [{ fields: additionalFields, label: 'Custom' }]
: []),
],
},
],
hooks: {
beforeChange: [
// Keys edited in the panel → clear the old Turnstile status, so a stale
// "not working" banner doesn't linger until the next form submission.
({ context, data, originalDoc }) => {
if (context?.ipalIntegrationStatus || !data) {return data}
const changed = (k: string) => k in data && data[k] !== originalDoc?.[k]
if (changed('turnstileSecretKey') || changed('turnstileSiteKey')) {
data.turnstileStatus = { checkedAt: null, code: null, message: null, since: null, state: null }
}
return data
},
],
},
label: 'Site Integrations',
}
}