react-audit(família 2): view model mínimo cruza o fio RSC — PetitionForm.tsx:29 deixa de receber o doc Petition inteiro (richText/consent/tracking ficam no server)

This commit is contained in:
Francisco Solla 2026-08-25 12:17:12 -03:00
parent e273e9ecfa
commit 34c04d6966
3 changed files with 16 additions and 4 deletions

View file

@ -237,7 +237,11 @@ export default async function Page({ params }: { params: Promise<{ id: string }>
<div className="rounded-xl border border-border bg-card p-5 text-card-foreground shadow-[0_24px_60px_rgb(122_25_18/0.12)] sm:p-7">
<PetitionForm
id="formulario"
petition={petition}
petition={{
id: petition.id,
title: petition.title,
form: { title: petition.form.title, subtitle: petition.form.subtitle },
}}
consentHTML={consentHTML}
facebookPixelId={facebookPixelId ?? undefined}
/>

View file

@ -11,7 +11,6 @@ import {
} from '@/components/ui/field'
import { trackMetaLead } from '@/lib/facebookPixel'
import { petitionFormSchema, type PetitionFormInput } from '@/lib/schemas/petition-form'
import { Petition } from '@/payload-types'
import { zodResolver } from '@hookform/resolvers/zod'
import { useState, useTransition } from 'react'
import { FormProvider, useForm, type SubmitHandler } from 'react-hook-form'
@ -26,9 +25,18 @@ import { StateSelect } from './StateSelect'
import { Button } from './ui/button'
import { Textarea } from './ui/textarea'
// View model — the server page selects only the fields this form renders, so
// the full petition document (body richText, consent relation, tracking,
// timestamps) never crosses the RSC wire into this client component.
type PetitionFormPetition = {
id: string
title: string
form: { title?: string | null; subtitle?: string | null }
}
interface PetitionFormProps {
id: string
petition: Petition
petition: PetitionFormPetition
consentHTML: string
facebookPixelId?: string
}

View file

@ -31,7 +31,7 @@ vi.mock('@/lib/facebookPixel', async (importOriginal) => {
const PIXEL_ID = '123456789012345'
const petition = {
id: 1,
id: '1',
title: 'Pela manutenção do Hospital do Subúrbio',
form: { title: 'Assine a petição', subtitle: '' },
} as unknown as Petition