mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 15:13:07 +00:00
format + e2e prewarm for pledge autosave routes
This commit is contained in:
parent
7d89356710
commit
c95d88562e
7 changed files with 24 additions and 23 deletions
|
|
@ -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`.
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Reference in a new issue