format + e2e prewarm for pledge autosave routes

This commit is contained in:
Cursor Agent 2026-08-03 00:11:22 +00:00
parent 7d89356710
commit c95d88562e
No known key found for this signature in database
7 changed files with 24 additions and 23 deletions

View file

@ -31,9 +31,9 @@ flowchart LR
**Opções consideradas:**
| | A — Reusar panels atuais (cards + forms) | B — Lista densa + B9 cell autosave + JSON routes | C — CampaignTable completo com colunas B17 |
| --- | --- | --- | --- |
| | Rápido mas cards + Salvar | Alinha B9 e aceite | Overkill sem picker de colunas |
| | A — Reusar panels atuais (cards + forms) | B — Lista densa + B9 cell autosave + JSON routes | C — CampaignTable completo com colunas B17 |
| --- | ---------------------------------------- | ------------------------------------------------ | ------------------------------------------ |
| | Rápido mas cards + Salvar | Alinha B9 e aceite | Overkill sem picker de colunas |
**Recomendação:** B — lista densa com `CampaignCellEditOverlay` + `useCampaignCellAutosave`; writes via `declareVotes`/`estimateVotes` existentes; revalidate v2 via `revalidateMunicipalityListPaths`.

View file

@ -8,8 +8,8 @@ import {
VOTE_PLEDGE_LEADERSHIP_REQUIRED_MESSAGE,
VOTE_PLEDGE_MUNICIPALITY_NOT_LINKED_MESSAGE,
} from '@/lib/schemas/votePledge'
import { revalidateMunicipalityListPaths } from '@/utilities/municipality/municipalityRevalidation'
import { campaignJsonMutationRoute } from '@/utilities/campaignJsonMutationRoute'
import { revalidateMunicipalityListPaths } from '@/utilities/municipality/municipalityRevalidation'
import type { MunicipalityPledgeDeclaredVotesResponse } from './types'

View file

@ -1,4 +1,5 @@
export const MUNICIPALITY_PLEDGE_DECLARED_VOTES_ENDPOINT = '/campanha/municipios/pledge-declared-votes'
export const MUNICIPALITY_PLEDGE_DECLARED_VOTES_ENDPOINT =
'/campanha/municipios/pledge-declared-votes'
export type MunicipalityPledgeDeclaredVotesResponse =
| { status: 'success'; message: string; savedDeclaredVotes: number; pledgeId: number }

View file

@ -3,13 +3,13 @@ import { z } from 'zod'
import { estimateVotes } from '@/app/(campaign)/campanha/actions/votePledge'
import { positiveRelationshipId } from '@/lib/schemas/primitives'
import { toVoteEstimateScenarioViewModel } from '@/lib/voteEstimate'
import {
VOTE_PLEDGE_ESTIMATE_STAFF_MESSAGE,
voteEstimateScenarioFieldsSchema,
} from '@/lib/schemas/votePledge'
import { revalidateMunicipalityListPaths } from '@/utilities/municipality/municipalityRevalidation'
import { toVoteEstimateScenarioViewModel } from '@/lib/voteEstimate'
import { campaignJsonMutationRoute } from '@/utilities/campaignJsonMutationRoute'
import { revalidateMunicipalityListPaths } from '@/utilities/municipality/municipalityRevalidation'
import type { MunicipalityPledgeEstimatedVotesResponse } from './types'
@ -26,8 +26,7 @@ export const POST = campaignJsonMutationRoute(
{
bodySchema,
safeMessages: [VOTE_PLEDGE_ESTIMATE_STAFF_MESSAGE],
genericMessage:
'Não foi possível salvar a estimativa. Verifique seu acesso e tente novamente.',
genericMessage: 'Não foi possível salvar a estimativa. Verifique seu acesso e tente novamente.',
},
async ({ pledgeId, estimatedVotes }) => {
const pledge = await estimateVotes({

View file

@ -54,17 +54,18 @@ const MunicipalityV2EstimatedVotesCellEditable = ({
)
const { open, onOpenChange, value, change, isPending, errorMessage, statusMessage } =
useCampaignCellAutosave<VoteEstimateScenarioViewModel, MunicipalityPledgeEstimatedVotesResponse>(
{
value: estimatedVotes,
equals: voteEstimatesEqual,
endpoint: MUNICIPALITY_PLEDGE_ESTIMATED_VOTES_ENDPOINT,
buildBody: (votes) => ({ pledgeId: pledgeID, estimatedVotes: votes }),
readSaved: (payload) => payload.savedEstimatedVotes,
errorMessage: SAVE_ERROR_MESSAGE,
pendingMessage: 'Salvando estimativa.',
},
)
useCampaignCellAutosave<
VoteEstimateScenarioViewModel,
MunicipalityPledgeEstimatedVotesResponse
>({
value: estimatedVotes,
equals: voteEstimatesEqual,
endpoint: MUNICIPALITY_PLEDGE_ESTIMATED_VOTES_ENDPOINT,
buildBody: (votes) => ({ pledgeId: pledgeID, estimatedVotes: votes }),
readSaved: (payload) => payload.savedEstimatedVotes,
errorMessage: SAVE_ERROR_MESSAGE,
pendingMessage: 'Salvando estimativa.',
})
const [focusedScenario, setFocusedScenario] = useState<VoteEstimateScenario>('central')

View file

@ -20,9 +20,7 @@ export const MunicipalityV2NetworkSection = ({ network }: MunicipalityV2NetworkS
<div className="flex flex-col gap-1">
<h2 id="municipio-v2-rede-title" className="text-base font-medium text-muted-foreground">
Rede
{network.totalCount > 0
? ` (${formatElectionNumber(network.totalCount)})`
: ''}
{network.totalCount > 0 ? ` (${formatElectionNumber(network.totalCount)})` : ''}
</h2>
<p className="text-sm text-muted-foreground">
Quem segura o município — ajuste declarado e estimado sem trocar de aba.

View file

@ -32,6 +32,8 @@ test('prewarms shared Next route bundles sequentially', async ({ request }) => {
'/campanha/municipios/advisors',
'/campanha/municipios/engagement-level',
'/campanha/municipios/expected-votes',
'/campanha/municipios/pledge-declared-votes',
'/campanha/municipios/pledge-estimated-votes',
'/campanha/municipios/political-trend',
'/campanha/liderancas/support-status',
'/campanha/webauthn/login-options',