teqo/src/components/campaign/PlazaPledgesPanel.tsx
Francisco Ignácio Fontoura Solla cf13c441aa Remodel /campanha around predefined Praças replacing electoral nuclei.
436 seeded Praças (municipality-based; per-TSE-zone in Salvador/Camaçari) become
the operational unit; roles renamed to coordinator/advisor/leader with advisors
scoped to administered Praças. Leadership is one record per person across many
Praças/organizations; vote pledges split leader-declared vs staff-estimated
(estimates never serialized to leaders). Adds organizations, demand workflow
with staff-only cost/receipts, action-plan results with deputy presence, manual
political trend, multi-candidate comparison and the diverging red/white/blue
map mode. Migration 20260721_020109_remodel_plazas deliberately resets the
campaign vertical in production (public site untouched); test suite ported to
the new model (unit 187 / int 306 / e2e 9 green).
2026-07-21 02:28:00 -03:00

94 lines
3.8 KiB
TypeScript

import { PledgeEstimateForm } from '@/components/campaign/PledgeEstimateForm'
import { Badge } from '@/components/ui/Badge'
import type { CampaignFormActionState } from '@/utilities/campaignFormActionError'
import type { StaffPledgeRow } from '@/utilities/votePledgeData'
const voteFormatter = new Intl.NumberFormat('pt-BR')
const dateFormatter = new Intl.DateTimeFormat('pt-BR')
type PlazaPledgesPanelProps = {
pledges: StaffPledgeRow[]
estimateFormAction: (
state: CampaignFormActionState,
formData: FormData,
) => Promise<CampaignFormActionState>
}
/** Staff-only: declared vs estimated votes per leadership in this plaza. */
export const PlazaPledgesPanel = ({ pledges, estimateFormAction }: PlazaPledgesPanelProps) => {
const declaredTotal = pledges.reduce((total, pledge) => total + pledge.declaredVotes, 0)
const effectiveTotal = pledges.reduce(
(total, pledge) => total + (pledge.estimatedVotes ?? pledge.declaredVotes),
0,
)
return (
<section
aria-labelledby="plaza-pledges-title"
className="flex flex-col gap-4 rounded-xl border p-4"
>
<div className="flex flex-col gap-1">
<h2 id="plaza-pledges-title" className="text-base font-medium">
Votos declarados pelas lideranças
</h2>
<p className="text-sm text-muted-foreground">
A liderança informa quantos votos traz; a assessoria registra a estimativa real. A
liderança nunca vê o valor estimado.
</p>
</div>
{pledges.length ? (
<>
<dl className="grid grid-cols-2 gap-3">
<div className="rounded-lg bg-muted/40 px-3 py-2">
<dt className="text-xs font-medium text-muted-foreground">Total declarado</dt>
<dd className="text-lg font-medium tabular-nums">
{voteFormatter.format(declaredTotal)}
</dd>
</div>
<div className="rounded-lg bg-muted/40 px-3 py-2">
<dt className="text-xs font-medium text-muted-foreground">Total estimado</dt>
<dd className="text-lg font-medium tabular-nums">
{voteFormatter.format(effectiveTotal)}
</dd>
</div>
</dl>
<ul className="flex flex-col gap-4">
{pledges.map((pledge) => (
<li key={pledge.id} className="flex flex-col gap-3 rounded-lg border p-3">
<div className="flex flex-wrap items-center justify-between gap-2">
<div className="flex flex-col">
<span className="font-medium">{pledge.contactName}</span>
<span className="text-sm text-muted-foreground">
Declarou {voteFormatter.format(pledge.declaredVotes)} votos
{pledge.declaredAt
? ` em ${dateFormatter.format(new Date(pledge.declaredAt))}`
: ''}
</span>
</div>
{pledge.estimatedVotes == null ? (
<Badge variant="estimate-pending">Sem estimativa</Badge>
) : (
<Badge variant="estimate-confirmed">
Estimado: {voteFormatter.format(pledge.estimatedVotes)}
</Badge>
)}
</div>
<PledgeEstimateForm
pledgeID={pledge.id}
currentEstimatedVotes={pledge.estimatedVotes}
currentEstimateNote={pledge.estimateNote}
formAction={estimateFormAction}
/>
</li>
))}
</ul>
</>
) : (
<p className="text-sm text-muted-foreground">
Nenhuma liderança declarou votos nesta Praça ainda.
</p>
)}
</section>
)
}