All checks were successful
CI (PR) / checks (pull_request) Successful in 15m47s
PR Ready + auto-merge / ready-automerge (pull_request) Successful in 16m1s
Promote plan-issue Related on main merge / plan-issue-ready (pull_request) Has been skipped
Main merge flips claimed issues to done + in-prod / issue-done (pull_request) Successful in 21s
e2e: stub hermético de connect.facebook.net no guard compartilhado (specs paralelos renderizam a home com o pixel); advisory lock no Postgres serializando o login do usuário de teste (Payload perde sessão em login concorrente read-modify-write — classe documentada no webauthn); seedTestUser vira create-if-missing (sem janela de usuário ausente nem reset de senha); Lead do form protegido do catch de erro (tracking nunca falha uma captura commitada); descrição do campo compartilhada; unidade nova campaignNewsletterLead cobre exatamente um Lead no sucesso.
130 lines
2.9 KiB
TypeScript
130 lines
2.9 KiB
TypeScript
import {
|
|
FACEBOOK_PIXEL_ID_DESCRIPTION,
|
|
normalizeFacebookPixelId,
|
|
validateFacebookPixelId,
|
|
} from '@/lib/facebookPixel'
|
|
import { payloadAdminOnly } from '@/utilities/campaignAccess'
|
|
import { revalidateDocumentById } from '@/utilities/documents'
|
|
import type { CollectionConfig } from 'payload'
|
|
|
|
const slug = 'petition'
|
|
|
|
export const Petition: CollectionConfig<typeof slug> = {
|
|
slug,
|
|
labels: {
|
|
singular: 'Abaixo-assinado',
|
|
plural: 'Abaixo-assinados',
|
|
},
|
|
admin: {
|
|
group: 'Abaixo-assinados',
|
|
useAsTitle: 'title',
|
|
livePreview: {
|
|
url: ({ data }) => `/abaixo-assinado/${data.id}`,
|
|
},
|
|
},
|
|
versions: {
|
|
drafts: {
|
|
schedulePublish: true,
|
|
},
|
|
maxPerDoc: 5,
|
|
},
|
|
access: {
|
|
read: () => true,
|
|
readVersions: payloadAdminOnly,
|
|
create: payloadAdminOnly,
|
|
update: payloadAdminOnly,
|
|
delete: payloadAdminOnly,
|
|
},
|
|
hooks: {
|
|
beforeChange: [
|
|
({ data }) => {
|
|
if (data?.tracking?.facebookPixelId != null) {
|
|
data.tracking.facebookPixelId = normalizeFacebookPixelId(data.tracking.facebookPixelId)
|
|
}
|
|
return data
|
|
},
|
|
],
|
|
afterChange: [
|
|
({ doc, previousDoc, operation }) => {
|
|
// Admin create view creates the initial draft during render.
|
|
// Skip cache invalidation only for that first draft creation.
|
|
if (operation === 'create' && doc._status !== 'published') return
|
|
|
|
revalidateDocumentById(slug, previousDoc?.id ?? doc.id)
|
|
},
|
|
],
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'id',
|
|
type: 'text',
|
|
label: 'Trecho Identificador da URL',
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'title',
|
|
type: 'text',
|
|
label: 'Título',
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'subtitle',
|
|
type: 'text',
|
|
label: 'Subtítulo',
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'enabled',
|
|
type: 'checkbox',
|
|
label: 'Ativo',
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'body',
|
|
type: 'richText',
|
|
label: 'Corpo',
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'form',
|
|
type: 'group',
|
|
label: 'Formulário',
|
|
required: true,
|
|
fields: [
|
|
{
|
|
name: 'title',
|
|
type: 'text',
|
|
label: 'Título',
|
|
},
|
|
{
|
|
name: 'subtitle',
|
|
type: 'text',
|
|
label: 'Subtítulo',
|
|
},
|
|
{
|
|
name: 'consent',
|
|
type: 'relationship',
|
|
label: 'Consentimento',
|
|
relationTo: 'consent',
|
|
required: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'tracking',
|
|
type: 'group',
|
|
label: 'Rastreamento / Ads',
|
|
fields: [
|
|
{
|
|
name: 'facebookPixelId',
|
|
type: 'text',
|
|
label: 'ID do Pixel do Meta (Facebook)',
|
|
admin: {
|
|
description: FACEBOOK_PIXEL_ID_DESCRIPTION,
|
|
},
|
|
validate: validateFacebookPixelId,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
}
|