Closes the 'Feel the action' gaps (.cursor/rules/campanha-action-feedback.mdc): - BUG: action-plan task checkbox was optimistic but never revalidated — a successful toggle visually reverted when the transition ended. The action now revalidates the plan page; checkbox disables while pending - map compare + candidate compare picker: optimistic select value + useTransition; the map region dims with aria-busy and a live region instead of flashing the full-page skeleton - CampaignListPendingBoundary/CampaignListResults: one shared transition so filters (municípios/apoiadores/planos), pagination, demandas status chips (new CampaignFilterChips), and the name-search pages (new CampaignSearchForm on lideranças/organizações/dobradinhas) dim the RESULTS region, not only the control — children stay server-rendered (composition) - streaming: dashboard map section behind Suspense (KPI shell paints first; React cache() keeps the municipality scope shared, not reloaded); municipality detail tabs (elections/leaderships/updates) stream below the header; list-shaped loading.tsx for /municipios and /apoiadores - logout button gets a pending state; BahiaMap init shows a visible spinner (was sr-only)
170 lines
6.2 KiB
TypeScript
170 lines
6.2 KiB
TypeScript
import { ArrowRightIcon } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
|
|
import type { ReactNode } from 'react'
|
|
|
|
import { CampaignMetricStrip } from '@/components/campaign/CampaignMetricStrip'
|
|
import {
|
|
CampaignPageShell,
|
|
campaignPrioritySurfaceClassName,
|
|
} from '@/components/campaign/CampaignPageShell'
|
|
import { RecentlyVisitedCard } from '@/components/campaign/RecentlyVisitedCard'
|
|
import { Badge } from '@/components/ui/Badge'
|
|
import { Button } from '@/components/ui/button'
|
|
import { formatElectionNumber } from '@/lib/electionInsights'
|
|
import type { StaffDashboardView } from '@/utilities/campaignDashboardData'
|
|
import {
|
|
formatVoteEstimateEndpointsLabel,
|
|
voteEstimateScenarioLabels,
|
|
} from '@/utilities/voteEstimate'
|
|
|
|
const dateTimeFormatter = new Intl.DateTimeFormat('pt-BR', {
|
|
dateStyle: 'short',
|
|
timeStyle: 'short',
|
|
})
|
|
|
|
export const CampaignDashboard = ({
|
|
view,
|
|
userName,
|
|
mapSlot = null,
|
|
}: {
|
|
view: StaffDashboardView
|
|
userName: string
|
|
/** Server-streamed map section (composition keeps this component map-agnostic). */
|
|
mapSlot?: ReactNode
|
|
}) => (
|
|
<CampaignPageShell>
|
|
<header className="flex flex-col gap-1">
|
|
<h1 className="text-2xl font-semibold tracking-tight">Olá, {userName}</h1>
|
|
<p className="text-muted-foreground">
|
|
{view.role === 'advisor'
|
|
? 'Quadro das Praças sob sua assessoria.'
|
|
: 'Quadro geral da campanha por Praça.'}
|
|
</p>
|
|
</header>
|
|
|
|
{mapSlot}
|
|
|
|
<section
|
|
aria-label="Indicadores das Praças"
|
|
className={`rounded-xl ${campaignPrioritySurfaceClassName}`}
|
|
>
|
|
<CampaignMetricStrip
|
|
metrics={[
|
|
{
|
|
label: `${voteEstimateScenarioLabels.central} nas Praças`,
|
|
value: formatElectionNumber(view.staffVoteTotalByScenario.central),
|
|
detail: formatVoteEstimateEndpointsLabel(view.staffVoteTotalByScenario) ?? undefined,
|
|
emphasize: true,
|
|
},
|
|
{
|
|
label: 'Cobertura de assessoria',
|
|
value: `${view.withAdvisorCount} de ${view.municipalityCount} Praças`,
|
|
progress:
|
|
view.municipalityCount > 0
|
|
? Math.round((view.withAdvisorCount / view.municipalityCount) * 100)
|
|
: undefined,
|
|
},
|
|
{
|
|
label: 'Declarações sem estimativa',
|
|
value: formatElectionNumber(view.missingEstimateCount),
|
|
},
|
|
]}
|
|
/>
|
|
</section>
|
|
|
|
<div className="grid gap-6 lg:grid-cols-2">
|
|
<section
|
|
aria-labelledby="dashboard-missing-title"
|
|
className="flex flex-col gap-3 rounded-xl border p-4"
|
|
>
|
|
<div className="flex items-center justify-between gap-2">
|
|
<h2 id="dashboard-missing-title" className="text-base font-medium">
|
|
Declarações aguardando estimativa
|
|
</h2>
|
|
<Badge variant="estimate-pending">{view.missingEstimateCount}</Badge>
|
|
</div>
|
|
{view.missingEstimates.length ? (
|
|
<ul className="flex flex-col gap-2">
|
|
{view.missingEstimates.map((item) => (
|
|
<li key={item.pledgeID} className="flex items-center justify-between gap-2">
|
|
<div className="flex min-w-0 flex-col">
|
|
<span className="truncate font-medium">{item.contactName}</span>
|
|
<span className="truncate text-sm text-muted-foreground">
|
|
{item.municipalityName} · declarou {formatElectionNumber(item.declaredVotes)}{' '}
|
|
votos
|
|
</span>
|
|
</div>
|
|
<Button asChild variant="ghost" className="min-h-11 shrink-0">
|
|
<Link href={`/campanha/municipios/${item.municipalitySlug}`}>Revisar</Link>
|
|
</Button>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
) : (
|
|
<p className="text-sm text-muted-foreground">
|
|
Todas as declarações do seu escopo têm estimativa registrada.
|
|
</p>
|
|
)}
|
|
</section>
|
|
|
|
<section
|
|
aria-labelledby="dashboard-updates-title"
|
|
className="flex flex-col gap-3 rounded-xl border p-4"
|
|
>
|
|
<h2 id="dashboard-updates-title" className="text-base font-medium">
|
|
Últimas atualizações de campo
|
|
</h2>
|
|
{view.recentUpdates.length ? (
|
|
<ul className="flex flex-col gap-2">
|
|
{view.recentUpdates.map((update) => (
|
|
<li key={update.id} className="flex items-center justify-between gap-2">
|
|
<div className="flex min-w-0 flex-col">
|
|
<span className="truncate font-medium">{update.municipalityName}</span>
|
|
<span className="truncate text-sm text-muted-foreground">
|
|
{update.authorName} · {dateTimeFormatter.format(new Date(update.createdAt))}
|
|
</span>
|
|
</div>
|
|
<Button asChild variant="ghost" className="min-h-11 shrink-0">
|
|
<Link href={`/campanha/municipios/${update.municipalitySlug}?tab=updates`}>
|
|
Abrir
|
|
</Link>
|
|
</Button>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
) : (
|
|
<p className="text-sm text-muted-foreground">Nenhuma atualização registrada ainda.</p>
|
|
)}
|
|
</section>
|
|
</div>
|
|
|
|
{view.priorityMunicipalities.length ? (
|
|
<section aria-labelledby="dashboard-priority-title" className="flex flex-col gap-3">
|
|
<h2 id="dashboard-priority-title" className="text-base font-medium">
|
|
Praças prioritárias
|
|
</h2>
|
|
<ul className="flex flex-wrap gap-2">
|
|
{view.priorityMunicipalities.map((municipality) => (
|
|
<li key={municipality.slug}>
|
|
<Button asChild variant="outline" className="min-h-11">
|
|
<Link href={`/campanha/municipios/${municipality.slug}`}>{municipality.name}</Link>
|
|
</Button>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</section>
|
|
) : null}
|
|
|
|
<RecentlyVisitedCard now={new Date()} />
|
|
|
|
<div>
|
|
<Button asChild className="min-h-11">
|
|
<Link href="/campanha/municipios">
|
|
Ver todas as Praças
|
|
<ArrowRightIcon data-icon="inline-end" aria-hidden="true" />
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
</CampaignPageShell>
|
|
)
|