Merge pull request #110 from fsolla/cursor/pool-i105-88d1d9e1-68c5
B97 — Salvar tendência fecha o wizard (não volta ao começo)
This commit is contained in:
commit
36b39ffdd9
4 changed files with 38 additions and 6 deletions
|
|
@ -35,7 +35,7 @@ import { CAMPAIGN_HOME } from '@/lib/campaignPaths'
|
|||
import {
|
||||
buildPoliticalTrendNotePrefill,
|
||||
resolvePoliticalTrendNotePrefillSource,
|
||||
selectablePoliticalTrendStatuses,
|
||||
resolveWizardTrendNoteDestination,
|
||||
} from '@/lib/politicalTrendWizardUi'
|
||||
import { toVoteEstimateScenarioViewModel } from '@/lib/voteEstimate'
|
||||
import config from '@/payload.config'
|
||||
|
|
@ -189,10 +189,13 @@ export default async function CampaignActionWizardPage({
|
|||
}
|
||||
|
||||
if (trendStatus) {
|
||||
if (
|
||||
trendStatus === currentStatus ||
|
||||
!selectablePoliticalTrendStatuses(currentStatus).includes(trendStatus)
|
||||
) {
|
||||
const noteDestination = resolveWizardTrendNoteDestination(trendStatus, currentStatus)
|
||||
|
||||
if (noteDestination === 'home') {
|
||||
redirect(CAMPAIGN_HOME)
|
||||
}
|
||||
|
||||
if (noteDestination === 'choice') {
|
||||
redirect(
|
||||
wizardTrendHref(slug, municipalitySlug, undefined, entryAction, prefillExtraParams),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ export const WizardTrendNoteStep = ({
|
|||
|
||||
useCampaignFormSuccessToast(state, () => {
|
||||
recordLastActedMunicipality(municipalitySlug)
|
||||
router.push(CAMPAIGN_HOME)
|
||||
router.replace(CAMPAIGN_HOME)
|
||||
})
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -41,6 +41,28 @@ export const selectablePoliticalTrendStatuses = (
|
|||
? politicalTrendStatuses.filter((status) => status !== currentStatus)
|
||||
: [...politicalTrendStatuses]
|
||||
|
||||
/** Where the change-trend wizard should land when `tendencia=` is present. */
|
||||
export type WizardTrendNoteDestination = 'note' | 'choice' | 'home'
|
||||
|
||||
/**
|
||||
* `home` when the query trend already matches the persisted status — covers
|
||||
* post-save RSC refresh (B97) and stale deep-links; never loops back to choice.
|
||||
*/
|
||||
export const resolveWizardTrendNoteDestination = (
|
||||
trendStatus: PoliticalTrendStatusValue,
|
||||
currentStatus: PoliticalTrendStatusValue | null,
|
||||
): WizardTrendNoteDestination => {
|
||||
if (trendStatus === currentStatus) {
|
||||
return 'home'
|
||||
}
|
||||
|
||||
if (!selectablePoliticalTrendStatuses(currentStatus).includes(trendStatus)) {
|
||||
return 'choice'
|
||||
}
|
||||
|
||||
return 'note'
|
||||
}
|
||||
|
||||
export const resolveWizardTrendSkip = (): WizardTrendSkipAction => ({
|
||||
label: WIZARD_TREND_SKIP_LABEL,
|
||||
href: CAMPAIGN_HOME,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import {
|
|||
import {
|
||||
buildPoliticalTrendNotePrefill,
|
||||
resolvePoliticalTrendNotePrefillSource,
|
||||
resolveWizardTrendNoteDestination,
|
||||
resolveWizardTrendSkip,
|
||||
selectablePoliticalTrendStatuses,
|
||||
WIZARD_TREND_SKIP_LABEL,
|
||||
|
|
@ -28,6 +29,12 @@ describe('politicalTrendWizardUi', () => {
|
|||
expect(selectablePoliticalTrendStatuses('desfavoravel')).toEqual(['favoravel', 'neutra'])
|
||||
})
|
||||
|
||||
it('resolves the note-step destination without looping to choice after save', () => {
|
||||
expect(resolveWizardTrendNoteDestination('favoravel', 'neutra')).toBe('note')
|
||||
expect(resolveWizardTrendNoteDestination('favoravel', 'favoravel')).toBe('home')
|
||||
expect(resolveWizardTrendNoteDestination('favoravel', null)).toBe('note')
|
||||
})
|
||||
|
||||
it('always exposes skip to abandon the trend change', () => {
|
||||
expect(resolveWizardTrendSkip()).toEqual({
|
||||
label: WIZARD_TREND_SKIP_LABEL,
|
||||
|
|
|
|||
Loading…
Reference in a new issue