96 lines
1.9 KiB
TypeScript
96 lines
1.9 KiB
TypeScript
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,
|
|
},
|
|
hooks: {
|
|
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,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
}
|