mirror of
https://github.com/fsolla/teqo.git
synced 2026-12-02 13:13:06 +00:00
A ferramenta de abaixo-assinado já existia, mas a petição do PL não tinha caminho reproduzível fora do dump legado: produção só carregava as três petições antigas editadas no admin. O conteúdo agora é versionado em scripts/lib/petitionPl5594Content.mjs e provisionado por pnpm seed:petition-pl-5594 — dry-run por padrão, create-if-missing por id, Consent whatsapp-inscricao resolvido por chave (fail-closed) e guards de escrita (PETITION_SEED_CONFIRM + TEQO_ENV casando o banco exato), sem sobrescrever edição do admin. O corpo traz os fatos do inteiro teor (autorização no registro, 5 exercícios de IR, sigilos bancário/fiscal/telefônico/de conexão, exclusão do conteúdo das comunicações, auditoria, LGPD e divulgação pela Justiça Eleitoral), a motivação de 18-19/10 sem acusar crime e o pedido sem prometer aprovação. A copy hardcoded do bloco do formulário deixa de falar em 'campanha'/'luta dos trabalhadores' e vira genérica. Prova: unit full 475 arquivos/5238 testes verdes, lint/typecheck/format limpos, seed aplicado e reaplicado em DB temporário (criação + no-op) e smoke real no navegador (página 200, consent, assinatura nº 1). Sem migration, collection, Consent novo ou mudança no fluxo de assinatura.
235 lines
9.5 KiB
TypeScript
235 lines
9.5 KiB
TypeScript
import { getSignatureCount } from '@/app/(frontend)/actions/getSignatureCount'
|
|
import { MetaPixel } from '@/components/MetaPixel'
|
|
import { PetitionForm } from '@/components/PetitionForm'
|
|
import { SignatureCounter } from '@/components/SignatureCounter'
|
|
import { normalizeFacebookPixelId } from '@/lib/facebookPixel'
|
|
import { getCachedDocumentById, getPetitionIds } from '@/utilities/documentReads'
|
|
import { extractFirstImageFromLexical } from '@/utilities/extractFirstImageFromLexical'
|
|
import { getCachedGlobal } from '@/utilities/globalReads'
|
|
import { resolveOgImage } from '@/utilities/ogImageReads'
|
|
import { absoluteSitePath, resolveSiteMetadata, truncate } from '@/utilities/seo'
|
|
import { convertLexicalToHTML } from '@payloadcms/richtext-lexical/html'
|
|
import type { Metadata } from 'next'
|
|
import Link from 'next/link'
|
|
import { notFound } from 'next/navigation'
|
|
import type { Article, WithContext } from 'schema-dts'
|
|
|
|
const MAX_DESCRIPTION_LENGTH = 200
|
|
|
|
export async function generateStaticParams() {
|
|
// Build-time enumeration only needs the ids — skip relationship population.
|
|
const ids = await getPetitionIds()
|
|
|
|
return ids.map((id) => ({ id }))
|
|
}
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: {
|
|
params: Promise<{ id: string }>
|
|
}): Promise<Metadata> {
|
|
const { id } = await params
|
|
const petition = await getCachedDocumentById('petition', id)()
|
|
|
|
if (!petition || !petition.enabled) {
|
|
return {}
|
|
}
|
|
|
|
const globalMetadata = await getCachedGlobal('metadata')()
|
|
const {
|
|
siteUrl,
|
|
siteName,
|
|
twitterCreator,
|
|
keywords: baseKeywords,
|
|
} = resolveSiteMetadata(globalMetadata)
|
|
const canonicalUrl = absoluteSitePath(siteUrl, `/abaixo-assinado/${petition.id}`)
|
|
|
|
const bodyImage = extractFirstImageFromLexical(petition.body)
|
|
const { url: imageUrl, media } = await resolveOgImage(bodyImage)
|
|
|
|
const description = truncate(petition.subtitle, MAX_DESCRIPTION_LENGTH)
|
|
const title = `${petition.title} | ${siteName}`
|
|
|
|
const keywords = [...baseKeywords, 'abaixo-assinado', 'petição', petition.title]
|
|
|
|
const ogImages = imageUrl
|
|
? [
|
|
{
|
|
url: imageUrl,
|
|
secureUrl: imageUrl,
|
|
width: media?.width ?? undefined,
|
|
height: media?.height ?? undefined,
|
|
alt: media?.alt,
|
|
type: media?.mimeType ?? undefined,
|
|
},
|
|
]
|
|
: []
|
|
|
|
return {
|
|
title,
|
|
description,
|
|
keywords,
|
|
...(canonicalUrl ? { alternates: { canonical: canonicalUrl } } : {}),
|
|
openGraph: {
|
|
type: 'article',
|
|
locale: 'pt-BR',
|
|
...(canonicalUrl ? { url: canonicalUrl } : {}),
|
|
siteName,
|
|
title,
|
|
description,
|
|
images: ogImages,
|
|
publishedTime: petition.createdAt,
|
|
modifiedTime: petition.updatedAt,
|
|
},
|
|
twitter: {
|
|
card: 'summary_large_image',
|
|
title,
|
|
description,
|
|
creator: twitterCreator,
|
|
images: ogImages.map((img) => img.url),
|
|
},
|
|
}
|
|
}
|
|
|
|
export default async function Page({ params }: { params: Promise<{ id: string }> }) {
|
|
const { id } = await params
|
|
const petition = await getCachedDocumentById('petition', id)()
|
|
|
|
if (!petition || !petition.enabled) {
|
|
return notFound()
|
|
}
|
|
|
|
const globalMetadata = await getCachedGlobal('metadata')()
|
|
const { siteUrl, siteName } = resolveSiteMetadata(globalMetadata)
|
|
const canonicalUrl = absoluteSitePath(siteUrl, `/abaixo-assinado/${petition.id}`)
|
|
|
|
const bodyImage = extractFirstImageFromLexical(petition.body)
|
|
const { url: ogImageUrl } = await resolveOgImage(bodyImage)
|
|
|
|
const jsonLd: WithContext<Article> = {
|
|
'@context': 'https://schema.org',
|
|
'@type': 'Article',
|
|
headline: petition.title,
|
|
description: truncate(petition.subtitle, MAX_DESCRIPTION_LENGTH),
|
|
inLanguage: 'pt-BR',
|
|
...(canonicalUrl
|
|
? {
|
|
url: canonicalUrl,
|
|
mainEntityOfPage: { '@type': 'WebPage', '@id': canonicalUrl },
|
|
}
|
|
: {}),
|
|
datePublished: petition.createdAt,
|
|
dateModified: petition.updatedAt,
|
|
...(ogImageUrl ? { image: [ogImageUrl] } : {}),
|
|
author: {
|
|
'@type': 'Organization',
|
|
name: siteName,
|
|
...(siteUrl ? { url: siteUrl } : {}),
|
|
},
|
|
publisher: {
|
|
'@type': 'Organization',
|
|
name: siteName,
|
|
...(siteUrl ? { url: siteUrl } : {}),
|
|
},
|
|
}
|
|
|
|
const consentHTML =
|
|
typeof petition.form.consent !== 'number'
|
|
? convertLexicalToHTML({ data: petition.form.consent.text })
|
|
: ''
|
|
|
|
const signatureCount = await getSignatureCount(petition.id)
|
|
const facebookPixelId = normalizeFacebookPixelId(petition.tracking?.facebookPixelId)
|
|
|
|
return (
|
|
<main
|
|
data-theme="petition"
|
|
className="h-screen w-screen overflow-y-auto bg-background text-foreground"
|
|
>
|
|
{facebookPixelId ? <MetaPixel pixelId={facebookPixelId} /> : null}
|
|
<script
|
|
type="application/ld+json"
|
|
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
|
|
/>
|
|
<section className="relative overflow-hidden border-b border-border bg-[var(--petition-hero)] text-[var(--petition-hero-foreground)]">
|
|
<div className="pointer-events-none absolute inset-0 bg-[radial-gradient(circle_at_top_right,var(--petition-hero-glow),transparent_40%),radial-gradient(circle_at_bottom_left,var(--petition-hero-depth),transparent_46%)]" />
|
|
<div className="relative mx-auto flex min-h-[72vh] w-full max-w-5xl items-center justify-center px-4 py-16 sm:px-6 sm:py-20 lg:px-8">
|
|
<div className="mx-auto flex max-w-3xl flex-col items-center space-y-6 text-center">
|
|
<span className="inline-flex w-fit rounded-full border border-white/20 bg-[var(--petition-hero-chip)] px-3 py-1 text-xs font-medium uppercase tracking-wider text-[var(--petition-hero-chip-foreground)]">
|
|
Abaixo-assinado
|
|
</span>
|
|
<h1 className="text-4xl font-bold leading-tight tracking-tight text-balance sm:text-5xl lg:text-6xl">
|
|
{petition.title}
|
|
</h1>
|
|
<h2 className="max-w-2xl border-none text-lg leading-relaxed text-[var(--petition-hero-muted)] sm:text-xl">
|
|
{petition.subtitle}
|
|
</h2>
|
|
<SignatureCounter
|
|
petitionId={petition.id}
|
|
initialCount={signatureCount}
|
|
variant="hero"
|
|
/>
|
|
<div className="flex flex-wrap justify-center gap-3 border-t border-white/15 pt-6">
|
|
<Link
|
|
href="#formulario"
|
|
className="inline-flex items-center justify-center rounded-md bg-[var(--petition-hero-cta)] px-5 py-2.5 text-sm font-semibold text-[var(--petition-hero-cta-foreground)] transition-colors hover:bg-[color-mix(in_oklab,var(--petition-hero-cta)_90%,white)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70"
|
|
>
|
|
Assinar agora
|
|
</Link>
|
|
<Link
|
|
href="#detalhes"
|
|
className="inline-flex items-center justify-center rounded-md border border-white/30 bg-transparent px-5 py-2.5 text-sm font-semibold text-white transition-colors hover:bg-white/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70"
|
|
>
|
|
Ler detalhes
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section
|
|
id="detalhes"
|
|
className="mx-auto w-full max-w-3xl px-4 py-14 sm:px-6 lg:px-8 lg:py-16"
|
|
>
|
|
<article
|
|
className="space-y-6 text-lg leading-8 text-foreground/90 [&_a]:font-medium [&_a]:text-primary [&_a]:underline-offset-4 [&_a:hover]:underline [&_blockquote]:border-l [&_blockquote]:border-border [&_blockquote]:pl-4 [&_blockquote]:text-muted-foreground [&_h1]:text-3xl [&_h1]:font-bold [&_h2]:border-none [&_h2]:text-2xl [&_h2]:font-semibold [&_h2]:text-primary [&_h3]:text-xl [&_h3]:font-semibold [&_li]:ml-5 [&_li]:list-disc [&_p]:text-lg [&_strong]:font-semibold [&_strong]:text-foreground"
|
|
dangerouslySetInnerHTML={{ __html: convertLexicalToHTML({ data: petition.body }) }}
|
|
/>
|
|
</section>
|
|
|
|
<section className="border-t border-border bg-[var(--petition-form-section)]">
|
|
<div className="mx-auto grid w-full max-w-5xl gap-8 px-4 py-14 sm:px-6 lg:grid-cols-[0.82fr_1.18fr] lg:px-8 lg:py-16">
|
|
<div className="space-y-4 self-start">
|
|
<span className="text-sm font-semibold uppercase tracking-wider text-primary">
|
|
Participe da mobilização
|
|
</span>
|
|
<h2 className="border-none text-left text-3xl font-bold leading-tight text-foreground sm:text-4xl">
|
|
Sua assinatura fortalece esta mobilização.
|
|
</h2>
|
|
<p className="text-base leading-7 text-muted-foreground">
|
|
Preencha o formulário para somar apoio público à proposta. Os dados serão usados
|
|
apenas para registrar sua participação e a comunicação de conteúdos relacionados.
|
|
</p>
|
|
<SignatureCounter
|
|
petitionId={petition.id}
|
|
initialCount={signatureCount}
|
|
variant="card"
|
|
/>
|
|
</div>
|
|
<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={{
|
|
id: petition.id,
|
|
title: petition.title,
|
|
form: { title: petition.form.title, subtitle: petition.form.subtitle },
|
|
}}
|
|
consentHTML={consentHTML}
|
|
facebookPixelId={facebookPixelId ?? undefined}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
)
|
|
}
|