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:** **Opções consideradas:**
| | A — Reusar panels atuais (cards + forms) | B — Lista densa + B9 cell autosave + JSON routes | C — CampaignTable completo com colunas B17 | | | 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 | | | 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`. **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_LEADERSHIP_REQUIRED_MESSAGE,
VOTE_PLEDGE_MUNICIPALITY_NOT_LINKED_MESSAGE, VOTE_PLEDGE_MUNICIPALITY_NOT_LINKED_MESSAGE,
} from '@/lib/schemas/votePledge' } from '@/lib/schemas/votePledge'
import { revalidateMunicipalityListPaths } from '@/utilities/municipality/municipalityRevalidation'
import { campaignJsonMutationRoute } from '@/utilities/campaignJsonMutationRoute' import { campaignJsonMutationRoute } from '@/utilities/campaignJsonMutationRoute'
import { revalidateMunicipalityListPaths } from '@/utilities/municipality/municipalityRevalidation'
import type { MunicipalityPledgeDeclaredVotesResponse } from './types' 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 = export type MunicipalityPledgeDeclaredVotesResponse =
| { status: 'success'; message: string; savedDeclaredVotes: number; pledgeId: number } | { 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 { estimateVotes } from '@/app/(campaign)/campanha/actions/votePledge'
import { positiveRelationshipId } from '@/lib/schemas/primitives' import { positiveRelationshipId } from '@/lib/schemas/primitives'
import { toVoteEstimateScenarioViewModel } from '@/lib/voteEstimate'
import { import {
VOTE_PLEDGE_ESTIMATE_STAFF_MESSAGE, VOTE_PLEDGE_ESTIMATE_STAFF_MESSAGE,
voteEstimateScenarioFieldsSchema, voteEstimateScenarioFieldsSchema,
} from '@/lib/schemas/votePledge' } from '@/lib/schemas/votePledge'
import { revalidateMunicipalityListPaths } from '@/utilities/municipality/municipalityRevalidation' import { toVoteEstimateScenarioViewModel } from '@/lib/voteEstimate'
import { campaignJsonMutationRoute } from '@/utilities/campaignJsonMutationRoute' import { campaignJsonMutationRoute } from '@/utilities/campaignJsonMutationRoute'
import { revalidateMunicipalityListPaths } from '@/utilities/municipality/municipalityRevalidation'
import type { MunicipalityPledgeEstimatedVotesResponse } from './types' import type { MunicipalityPledgeEstimatedVotesResponse } from './types'
@ -26,8 +26,7 @@ export const POST = campaignJsonMutationRoute(
{ {
bodySchema, bodySchema,
safeMessages: [VOTE_PLEDGE_ESTIMATE_STAFF_MESSAGE], safeMessages: [VOTE_PLEDGE_ESTIMATE_STAFF_MESSAGE],
genericMessage: genericMessage: 'Não foi possível salvar a estimativa. Verifique seu acesso e tente novamente.',
'Não foi possível salvar a estimativa. Verifique seu acesso e tente novamente.',
}, },
async ({ pledgeId, estimatedVotes }) => { async ({ pledgeId, estimatedVotes }) => {
const pledge = await estimateVotes({ const pledge = await estimateVotes({

View file

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

View file

@ -20,9 +20,7 @@ export const MunicipalityV2NetworkSection = ({ network }: MunicipalityV2NetworkS
<div className="flex flex-col gap-1"> <div className="flex flex-col gap-1">
<h2 id="municipio-v2-rede-title" className="text-base font-medium text-muted-foreground"> <h2 id="municipio-v2-rede-title" className="text-base font-medium text-muted-foreground">
Rede Rede
{network.totalCount > 0 {network.totalCount > 0 ? ` (${formatElectionNumber(network.totalCount)})` : ''}
? ` (${formatElectionNumber(network.totalCount)})`
: ''}
</h2> </h2>
<p className="text-sm text-muted-foreground"> <p className="text-sm text-muted-foreground">
Quem segura o município — ajuste declarado e estimado sem trocar de aba. 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/advisors',
'/campanha/municipios/engagement-level', '/campanha/municipios/engagement-level',
'/campanha/municipios/expected-votes', '/campanha/municipios/expected-votes',
'/campanha/municipios/pledge-declared-votes',
'/campanha/municipios/pledge-estimated-votes',
'/campanha/municipios/political-trend', '/campanha/municipios/political-trend',
'/campanha/liderancas/support-status', '/campanha/liderancas/support-status',
'/campanha/webauthn/login-options', '/campanha/webauthn/login-options',