mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-19 08:03:06 +00:00
B97 — Salvar tendência fecha wizard (redirect home quando status já aplicado)
Após salvar a nota, o RSC refresh via server action via redirecionava à etapa de escolha. Agora manda para Início nesse caso; o client usa no sucesso. Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
This commit is contained in:
parent
73f256e227
commit
5ce82e2229
4 changed files with 38 additions and 6 deletions
|
|
@ -35,7 +35,7 @@ import { CAMPAIGN_HOME } from '@/lib/campaignPaths'
|
||||||
import {
|
import {
|
||||||
buildPoliticalTrendNotePrefill,
|
buildPoliticalTrendNotePrefill,
|
||||||
resolvePoliticalTrendNotePrefillSource,
|
resolvePoliticalTrendNotePrefillSource,
|
||||||
selectablePoliticalTrendStatuses,
|
resolveWizardTrendNoteDestination,
|
||||||
} from '@/lib/politicalTrendWizardUi'
|
} from '@/lib/politicalTrendWizardUi'
|
||||||
import { toVoteEstimateScenarioViewModel } from '@/lib/voteEstimate'
|
import { toVoteEstimateScenarioViewModel } from '@/lib/voteEstimate'
|
||||||
import config from '@/payload.config'
|
import config from '@/payload.config'
|
||||||
|
|
@ -189,10 +189,13 @@ export default async function CampaignActionWizardPage({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trendStatus) {
|
if (trendStatus) {
|
||||||
if (
|
const noteDestination = resolveWizardTrendNoteDestination(trendStatus, currentStatus)
|
||||||
trendStatus === currentStatus ||
|
|
||||||
!selectablePoliticalTrendStatuses(currentStatus).includes(trendStatus)
|
if (noteDestination === 'home') {
|
||||||
) {
|
redirect(CAMPAIGN_HOME)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (noteDestination === 'choice') {
|
||||||
redirect(
|
redirect(
|
||||||
wizardTrendHref(slug, municipalitySlug, undefined, entryAction, prefillExtraParams),
|
wizardTrendHref(slug, municipalitySlug, undefined, entryAction, prefillExtraParams),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ export const WizardTrendNoteStep = ({
|
||||||
|
|
||||||
useCampaignFormSuccessToast(state, () => {
|
useCampaignFormSuccessToast(state, () => {
|
||||||
recordLastActedMunicipality(municipalitySlug)
|
recordLastActedMunicipality(municipalitySlug)
|
||||||
router.push(CAMPAIGN_HOME)
|
router.replace(CAMPAIGN_HOME)
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,28 @@ export const selectablePoliticalTrendStatuses = (
|
||||||
? politicalTrendStatuses.filter((status) => status !== currentStatus)
|
? politicalTrendStatuses.filter((status) => status !== currentStatus)
|
||||||
: [...politicalTrendStatuses]
|
: [...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 => ({
|
export const resolveWizardTrendSkip = (): WizardTrendSkipAction => ({
|
||||||
label: WIZARD_TREND_SKIP_LABEL,
|
label: WIZARD_TREND_SKIP_LABEL,
|
||||||
href: CAMPAIGN_HOME,
|
href: CAMPAIGN_HOME,
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import {
|
||||||
import {
|
import {
|
||||||
buildPoliticalTrendNotePrefill,
|
buildPoliticalTrendNotePrefill,
|
||||||
resolvePoliticalTrendNotePrefillSource,
|
resolvePoliticalTrendNotePrefillSource,
|
||||||
|
resolveWizardTrendNoteDestination,
|
||||||
resolveWizardTrendSkip,
|
resolveWizardTrendSkip,
|
||||||
selectablePoliticalTrendStatuses,
|
selectablePoliticalTrendStatuses,
|
||||||
WIZARD_TREND_SKIP_LABEL,
|
WIZARD_TREND_SKIP_LABEL,
|
||||||
|
|
@ -28,6 +29,12 @@ describe('politicalTrendWizardUi', () => {
|
||||||
expect(selectablePoliticalTrendStatuses('desfavoravel')).toEqual(['favoravel', 'neutra'])
|
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', () => {
|
it('always exposes skip to abandon the trend change', () => {
|
||||||
expect(resolveWizardTrendSkip()).toEqual({
|
expect(resolveWizardTrendSkip()).toEqual({
|
||||||
label: WIZARD_TREND_SKIP_LABEL,
|
label: WIZARD_TREND_SKIP_LABEL,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue