Todos os 7 blocos seguem EXATAMENTE o mesmo padrão. Aprenda uma vez, repita 7x.
Anatomia de um Bloco
- config.ts
- Component.tsx
- styles.module.css
1. config.ts - O que o cliente edita
import { Block } from 'payload'
export const SobreBlock: Block = {
slug: 'sobreBlock',
interfaceName: 'SobreBlockType',
fields: [
{ name: 'titulo', type: 'text', required: true },
{ name: 'texto', type: 'richText' },
{ name: 'imagem', type: 'upload', relationTo: 'media' },
],
}
2. Component.tsx - O que o usuário vê
import { SobreBlockType } from '@/payload-types'
import styles from './styles.module.css'
export const SobreBlockComponent = ({ titulo, texto, imagem }: SobreBlockType) => {
return (
<section className={styles.wrapper}>
<h2>{titulo}</h2>
{/* render richText */}
</section>
)
}
3. Registro no Pages.ts
// src/collections/Pages.ts
import { SobreBlock } from '@/blocks/SobreBlock/config'
import { HomeBlock } from '@/blocks/HomeBlock/config'
export const Pages: CollectionConfig = {
slug: 'pages',
fields: [
{
name: 'blocks',
type: 'blocks',
blocks: [HomeBlock, SobreBlock /* ... */],
},
],
}
4. RenderBlocks.tsx
// src/blocks/RenderBlocks.tsx
import { SobreBlockComponent } from '@/blocks/SobreBlock/Component'
import { HomeBlockComponent } from '@/blocks/HomeBlock/Component'
const blockComponents = {
sobreBlock: SobreBlockComponent,
homeBlock: HomeBlockComponent,
}
export const RenderBlocks = ({ blocks }) => {
return blocks.map((block, i) => {
const Block = blockComponents[block.blockType]
return Block ? <Block key={i} {...block} /> : null
})
}
Por que interfaceName?:
O Payload gera automaticamente o tipo TypeScript no payload-types.ts. Você importa ele no Component, sem duplicar tipagem.
1
1
Defina slug e fields que o cliente vai editar
2
1
npm run generate:types - vai criar SobreBlockType
3
1
Use o type gerado, nunca crie type manual